Prevent git merge when conflict exists

5

When I'm using GitHub for Desktop, and do a pull or push, the App just informs you that a file is in conflict and nothing happens. but when I use gitbash, it automatically starts a merge.

I would like every time I make a git pull or git push in gitbash, the system just gives an error informing the file that is in conflict and stops the process, similar to GitHub for Desktop.

I prefer that whenever a file is in conflict, the process is, copy the developer changes to the notepad, clear all changes ( git checkout -- . , ...), perform a new git pull, the developer changes to the new file, and try a git add / git commit / git push .

Inescapably, whenever a developer does a git push in gitbash, a merge automatically pops up, it always ends up committing, and it always breaks the project.

My question is: do you have a command for git pull and git push that prevents the merge, and if there is a conflict, do not download or send the changes to the origin? Example: git pull --strategy="abort case conflict" ?

    
asked by anonymous 11.06.2018 / 12:06

1 answer

2

You can instruct developers, when they detect the problem, to abort the merge of git pull with conflicts, using:

git merge --abort

In the worst case, you can create some script or command alias that does this for you when the conflict is detected, instructing all developers to use it. Thinking about an almost pseudocode for this script, it would look like:

git pull | grep 'Unmerged paths' &> /dev/null
if [ $? == 0 ]; then
   git merge --abort
fi

And the name of the script / command could be something like git-pull .

Much of what you said refers to developers not understanding how the Git conflict resolution process works. Without everyone learning properly how Git works, it's hard to think of a good solution.

    
24.07.2018 / 22:14