Prevent git merge when conflict exists

Asked

Viewed 103 times

5

When I’m using Github for Desktop, and I pull or push, the App just tells me that a file is in conflict and nothing happens. but when I use gitbash, it automatically starts a merge.

I’d like you to always make one git pull or git push on gitbash, the system just made an error stating the file is in conflict and stopped 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 note block, clear all changes (git checkout -- ., ...), perform a new git pull, pass developer changes to the new file, and try a git add / git commit / git push.

In an inescapable way, whenever a developer makes a git push on gitbash, a merge automatically appears, he always ends up eating, and always breaks the project.

My question is: do you have any commands for git pull and git push that prevent merge, and if there is a conflict, don’t download and don’t send the changes to origin? Example: git pull --strategy="abort case conflict"?

1 answer

2


You can instruct developers who, when detecting the problem, abort the merge of git pull conflict-ridden, 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 of an almost pseudocode for this script, it would be:

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 how Git works properly, it’s hard to think of a good solution.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.