Search code examples
gitconflict

How to avoid conflict in GIT


Background: We are using GIT as a PHP deploy system (in addition to SCM features). Once we have a stable source code version, we launch a script that is executed in the production server to synchronize with the latest version. This production server has two branches:

  • master: that's the latest version of the source code without any production customization.
  • pro: that's a master child branch that only exists in this production server and has some small changes necessary to run the app in the given server (i.e. database access data, server name, etc).

NOTE: The main repository has more branches and programmers have more branches, but the only branch used in production is master, the other are ignored and not synchronized.

The problem: There are about 100 copies of the source code in different servers with different configurations and there is a unique script that launches all "local" scripts. Until now local scripts have never failed due it's simplicity, a bit more than:

git checkout master
git pull
git checkout pro
git rebase master

(I've removed all non-GIT commands and the error checking)

but now all script have failed because there is a conflict between a change we have made in the main repository and a change that every local pro branch has (remember that the pro branch is not shared, just local to store some configuration).

Concretely, the problem has appeared when we have changed a couple of lines in a file called 'config.php' from this:

$db_user = 'user';
$db_password = 'password';

to this:

$db_user = 'other-user';
$db_password = 'other-password';

The conflict appears in the pro branch when the script executes the 'rebase' because the production server has a different value for these variables:

$db_user = 'pro-user';
$db_password = 'pro-password';

Of course the conflict is really easy to avoid "by hand" just ignoring the "new configuration" that comes from the repository (pro config shouldn't be changed).

The question is: how can I avoid this conflict? Because we don't want to resolve the conflict by hand on every ŝerver every time we find this kind of conflict. We can change the script without any problem if it's necessary, temporary or permanently to resolve the problem.


Solution

  • If you wish to override the conflicts by automatically selecting the content of pro's commits, after checking out pro, run with these parameters: git rebase -X theirs master.

    Note that the sides switch between merge and rebase, so when rebasing - ours becomes master, and theirs is the commits you have in your current branch which are not in master. Which is kind of counter-intuitive.