Abort a git merge on conflicts
October 21, 2020 ‐ 1 min read
When you pull in changes from your remote there is a chance you run into merge conflicts. If a merge can't be resolved using auto-merging your terminal can gets swamped with messages like:
CONFLICT (content): Merge conflict in ...
Ofcourse one option is to resolve the merge conflicts. However sometimes it is easier to just abort.
You can abort a git merge with conflicts with the following command.
$ git merge --abort
Now, to circumvent the merge conflicts you can use
fetch. If going down the road of resolving merge conflicts isn't an option.
Before you do this make sure that your changes are stashed.
You can fetch the latest changes from the remote, in this case called
origin, with the following command.
$ git fetch origin <branch>
To get these changes in your active branch you can do a hard reset which gives you the latest code from the remote you just fetched.
$ git reset --hard origin/<branch>