I\'m running into conflicts while trying to merge upstream changes back into my branch and I\'m not sure how to resolve them.
I created my own fork. I cloned it. I m
In Git there are cases merge refuses to even start in order to protect your local changes. This may happen in two cases:
You have uncommitted changes in you repository that conflict with merge. The git will refuse to do a merge with the following message:
error: Your local changes to the following files would be overwritten by merge: foo Please, commit your changes or stash them before you can merge. Aborting
Then you have to either commit the changes first (git commit -a
or git add
+ git commit
), or stash them away with git stash save
.
You are in the middle of some unfinished merge-y operation. There was some conflict, for example
Auto-merging foo CONFLICT (content): Merge conflict in foo Automatic merge failed; fix conflicts and then commit the result.
and you have not finished resolving conflicts (by editing files and marking them as resolved with git add
, or using some graphical merge tool via git mergetool
) and didn't create a final merge commit with git commit -a
, or aborted the merge with git reset --hard
(NOTE: this will discard all you changes, and you will loose work done on resolving conflicts!!!).
Or you have just run second git merge
too fast, or used git merge
instead of git commit
to create a merge commit.
error: 'merge' is not possible because you have unmerged files. hint: Fix them up in the work tree, hint: and then use 'git add/rm ' as hint: appropriate to mark resolution and make a commit, hint: or use 'git commit -a'. fatal: Exiting because of an unresolved conflict.
Resolve conflicts as described e.g. in old Fun with completing a merge article by Junio C Hamano and finalize a merge with git commit
, or discard a merge, or stash it away. Then if you meant to create this second merge, you can do it.
Sidenote: by default git-aware shell prompt shows if you are in the middle of merge, rebase or applying patches (git am
operation). You can also configure it to show if the working directory is dirty (different from latest version, i.e. HEAD).