134

git continues to confuse me with its unhelpful error warnings This one really deserves a prize:

git merge is not possible because you have unmerged files

My situation: My master branch on github was edited (directly in the browser) while my local master branch was also edited.

I wrongly suppose you could simply merge the two versions and be done with it, but also, I cannot merge - because my files are unmerged.

git merge remote/master

results in

error: merge is not possible because you have unmerged files.
hint: Fix them up in the work tree, and then use 'git add/rm <file>'
hint: as appropriate to mark resolution and make a commit.
fatal: Exiting because of an unresolved conflict.

So, after adding and committing the local change and then trying to merge again, I get:

merge: remote/master - not something we can merge

Clearly I am missing something essential here... Do I have the wrong idea about what merging means? How do I fix this issue of having a different remote master / local master branch?

1
  • Generally, it will tell you which file(s) specifically have a merge conflict. You can then open them up (while in merge mode with a decent editor like vscode or a JetBrains IDE) and see where the conflict is. There's not too much to it.
    – Harlin
    Commented Feb 13, 2023 at 19:25

10 Answers 10

86

I repeatedly had the same challenge sometime ago. This problem occurs mostly when you are trying to pull from the remote repository and you have some files on your local instance conflicting with the remote version, if you are using git from an IDE such as IntelliJ, you will be prompted and allowed to make a choice if you want to retain your own changes or you prefer the changes in the remote version to overwrite yours'. If you don't make any choice then you fall into this conflict. all you need to do is run:

git merge --abort # The unresolved conflict will be cleared off

And you can continue what you were doing before the break.

2
  • 20
    Fatal: there is no merge to abort
    – john k
    Commented Jul 27, 2020 at 17:47
  • 1
    I found that execute the command "git restore --staged <filename>" solved the problem for me.
    – DeSpeaker
    Commented Feb 6, 2022 at 17:48
42

The error message:

merge: remote/master - not something we can merge

is saying that Git doesn't recognize remote/master. This is probably because you don't have a "remote" named "remote". You have a "remote" named "origin".

Think of "remotes" as an alias for the url to your Git server. master is your locally checked-out version of the branch. origin/master is the latest version of master from your Git server that you have fetched (downloaded). A fetch is always safe because it will only update the "origin/x" version of your branches.

So, to get your master branch back in sync, first download the latest content from the git server:

git fetch

Then, perform the merge:

git merge origin/master

...But, perhaps the better approach would be:

git pull origin master

The pull command will do the fetch and merge for you in one step.

6
  • Thanks I didn't realise that pull also merges. I have done a fetch and a merge, but nothing seems to happen - although git now says everything is up to date. I expected the merge to show a 'merge conflict' where you have to manually edit the changes you want to keep?
    – Kokodoko
    Commented Mar 18, 2016 at 14:00
  • In this case, it looks like Git was able to peform the diff resolution for you...to be confident you have taken in what you intended a good "sanity check" tool that I use often is "gitk". It comes with the Git install so you should already have it. Just type "gitk" on your command terminal for a GUI-type view of your Git tree. Commented Mar 18, 2016 at 14:02
  • 1
    The merge inserted comments in my file, that look like this: <<<<<<<HEAD key:7234095827345093458. Perhaps git couldn't find my fileMerge tool and inserted these codes for me to resolve in a text editor?
    – Kokodoko
    Commented Mar 18, 2016 at 14:07
  • Yes, that sounds like a plausible reason for that to happen...if you wanted to re-do the merge (after fixing your merge-tool) you should be able to do: git reset --hard MERGE_HEAD to get back to your pre-merge state Commented Mar 18, 2016 at 14:11
  • Thanks, that already answers my question why I couldn't merge (I had to have the two different versions available first). What remains now is how to get git to automatically open "opendiff/fileMerge" in case of a conflict. I suppose that's a different question.
    – Kokodoko
    Commented Mar 18, 2016 at 14:27
30

It might be the Unmerged paths that cause

error: Merging is not possible because you have unmerged files.

If so, try:

git status

if it says

You have unmerged paths.

do as suggested: either resolve conflicts and then commit or abort the merge entirely with

git merge --abort

You might also see files listed under Unmerged paths, which you can resolve by doing

git rm <file>
3
  • 3
    It's just such an unhelpful error message.... In my case it mostly means that I have merge conflicts that have to be fixed manually. It would help a lot if the error message actually said that.
    – Kokodoko
    Commented Sep 11, 2020 at 9:57
  • after git status I'd to do git add path for Changes not staged for commit.
    – Prabs
    Commented Nov 22, 2020 at 14:04
  • git rm helped me
    – Kiran
    Commented Sep 16, 2022 at 9:54
10

The simple and safe way is to type git status into your terminal window/command prompt. This should show you the files that either need to be added or removed cmd of git status

and then you can either type git add followed by the file path (to add the file to your future commit) or remove them with git rm also followed by the file path (to remove the file from your future commit). To clarify, The latter command will not delete the file from your system.

After all the files in red are taken care of, you can commit and then push.

7

I also had similar problems.

My probblem: when I merge branch, and resolve conflicts with IDE, the IDE will show commit panel board normally, but it does not.

I think I have merged successfully, but when I push or pull,git remind me " commit your changes before merging" or "Updates were rejected because the tip of your current branch is behind".

My solution: git merge --continue

if you want to abort this merge ,you can also run git merge --abort

5

I ran into the same issue and couldn't decide between laughing or smashing my head on the table when I read this error...

What git really tries to tell you: "You are already in a merge state and need to resolve the conflicts there first!"

You tried a merge and a conflict occured. Then, git stays in the merge state and if you want to resolve the merge with other commands git thinks you want to execute a new merge and so it tells you you can't do this because of your current unmerged files...

You can leave this state with git merge --abort and now try to execute other commands.

In my case I tried a pull and wanted to resolve the conflicts by hand when the error occured...

3
  • 2
    Good to know I'm not the only one who is constantly baffled by git's cryptic error messages.
    – Kokodoko
    Commented May 12, 2017 at 16:09
  • getting every command rejected, after git merge --abort, git started to execute command Commented May 7, 2020 at 19:49
  • git is good as long as it works... otherwise just do rm -rf workspace and git checkout again. :). rather than wasting time on understanding cryptic messages by git
    – Stunner
    Commented Aug 9, 2021 at 8:04
3

Something that happened to me, if you tried to do merge before and resolved some conflicts on the incoming branch, git can do some changes on its own on your current branch, so try git status even if you are sure that no modifications have been made by yourself, then something like this might appear: They did it!

then simply do git add . git commit -m "message" and try to do the merge again

2

Another potential cause for this (Intellij was involved in my case, not sure that mattered though): trying to merge in changes from a main branch into a branch off of a feature branch.

In other words, merging "main" into "current" in the following arrangement:

main
  |
  --feature
      |
      --current

I resolved all conflicts and GiT reported unmerged files and I was stuck until I merged from main into feature, then feature into current.

-1

try

git add *
git commit -comment
git pull

Explanation git add * : Means you are adding all files that are not added' git commit -comment : You are committing file you have just added git pull : You are now getting changes from online version

2
  • @GertArnold , I have added explanation. Thanks for suggestion.
    – MUHINDO
    Commented Sep 16, 2022 at 17:39
  • Well, I think a commit will immediately cause merge conflicts in the described case. Commented Sep 16, 2022 at 18:23
-1

I managed to resolve this issue with these git commands in order:

git init   
git rm -r -f *  
git merge origin main  
git add *  
git commit -m 'merging'  
git pull

Not the answer you're looking for? Browse other questions tagged or ask your own question.