Cyberithub

[Solved]: "error: Pulling is not possible because you have unmerged files"

Advertisements

In this article, we will see how to solve "error: Pulling is not possible because you have unmerged files". It is not very uncommon to get this error while performing some git pull operations to accomplish a tasks. You may find this error occurring in various scenarios. For example, during git pull operation if you have any unmerged files due to conflict then it won't allow to perform any further pull until you resolve the conflict and merge the files. You will also see "Automatic merge failed; fix conflicts and then commit the result" error in that case.

Then you may see pulling error when you have done your changes to a branch and without adding and committing them, you are trying to pull another set of changes from a remote release branch. In this case also, you may see the same pulling error. Similarly, in few other cases as well you may see the same type of error. So here we are going to look into all possible solutions which you can take to solve this error whichever works best for you.

 

[Solved]: "error: Pulling is not possible because you have unmerged files"

[Solved]: "error: Pulling is not possible because you have unmerged files"

Also Read: How to Install curl on Ubuntu 22.04 LTS (Jammy Jellyfish)

Before looking into the list of solution steps, I would like to explain the error which I was facing so that it will make more sense and gives complete understanding about solving this kind of error. In my case, I was working on my local master branch and were trying to pull and merge all the changes from remote release branch rel-9.7 using git pull origin rel-9.7 --no-ff command. But then immediately I noticed "error: Pulling is not possible because you have unmerged files" on the output as shown below.

cyberithub@macos1066 ~ % git pull origin rel-9.7 --no-ff
warning: Pulling without specifying how to reconcile divergent branches is
discouraged. You can squelch this message by running one of the following
commands sometimes before your next pull:

git config pull.rebase false # merge (the default strategy)
git config pull.rebase true # rebase
git config pull.ff only # fast-forward only

You can replace "git config" with "git config --global" to set a default
preference for all repositories. You can also pass --rebase, --no-rebase,
or --ff-only on the command line to override the configured default per
invocation.

error: Pulling 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.

 

Solution 1: Fix conflict error manually

After getting above error, first thing that you have to do is to check the current status by running git status command as shown below.

cyberithub@macos1066 ~ % git status
On branch master
Your branch is up to date with 'origin/master'.

You have unmerged paths.
  (fix conflicts and run "git commit")
  (use "git merge --abort" to abort the merge)

Changes to be committed:
   modified: app/config/service/server.properties
   modified: app/config/service/plugin.yaml
   modified: app/config/service/env.yaml 

Unmerged paths:
 (use "git add <file>..." to mark resolution)
    both modified: app/config/service/config.yaml
    both modified: app/config/service/resource.yaml

As you can see from above output, there are few files which are added but not committed and there are few files which has conflict error and hence not added and committed yet. So before making a pull request, it is absolutely required to fix the conflict error and then add and commit the changes. You can check Solved "Automatic merge failed; fix conflicts and then commit the result" to know more about fixing the conflict error. Then after fixing the problem, you have to first add all the unmerged files by running git add . command from the root path as shown below.

cyberithub@macos1066 ~ % git add .

After adding files, if you check the status again using git status command then you will notice that now there will be no further files to add, just need to commit all the added files.

cyberithub@macos1066 ~ % git status 
On branch master
Your branch is up to date with 'origin/master'.

You have unmerged paths.
  (fix conflicts and run "git commit")
  (use "git merge --abort" to abort the merge)

Changes to be committed:
    modified: app/config/service/server.properties
    modified: app/config/service/plugin.yaml
    modified: app/config/service/env.yaml 
    modified: app/config/service/config.yaml
    modified: app/config/service/resource.yaml

Go ahead and commit all the added files by using git commit command along with the appropriate commit message as you can see below.

cyberithub@macos1066 ~ % git commit -m "Fixed conflict error" 
[master e733d63c] Fixed conflict error

Again if you run git status command then you will notice that this time it won't show anything else to commit.

cyberithub@macos1066 ~ % git status
On branch master
Your branch is ahead of 'origin/master' by 4 commits.
  (use "git push" to publish your local commits)

nothing to commit, working tree clean

Now that everything is added and commit, you can go ahead and try to pull the changes from remote branch. You should not see the same error again as you can see below.

cyberithub@macos1066 ~ % git pull origin rel-9.7 --no-ff 
warning: Pulling without specifying how to reconcile divergent branches is 
discouraged. You can squelch this message by running one of the following 
commands sometimes before your next pull: 

 git config pull.rebase false # merge (the default strategy) 
 git config pull.rebase true # rebase 
 git config pull.ff only # fast-forward only 

You can replace "git config" with "git config --global" to set a default 
preference for all repositories. You can also pass --rebase, --no-rebase, 
or --ff-only on the command line to override the configured default per 
invocation. 

From https://apps.cyberithub.com/scm/hcm/sample-service 
*branch         rel-9.7 -> FETCH_HEAD 
Already up to date.

 

Solution 2: Reset HEAD

There are other solutions that you may think to apply to fix the merge conflict error in which one of the potential dangerous solution is to reset HEAD using git reset --hard HEAD command as shown below. However it is important to note here that this step might solve the error but it may not solve the problem and probably may arise another problem of erasing all your past work or uncommitted changes if not used diligently. Hence kindly be sure before using this solution.

cyberithub@macos1066 ~ % git reset --hard HEAD

 

Solution 3: Perform rebase

Another very useful solution which you could thought of using is that you can pull the remote updates and combine them in your local work using git pull --rebase operation as shown below.

cyberithub@macos1066 ~ % git pull --rebase

Then you can reset HEAD pointer using git reset HEAD~1 command and verify if it solves your "error: Pulling is not possible because you have unmerged files"

cyberithub@macos1066 ~ % git reset HEAD~1

 

Solution 4: Stash and Clean

Another very similar approach you can take is that shelves your changes for the time being using git stash command to work on something else.

cyberithub@macos1066 ~ % git stash

Then pull your latest changes using git pull command as shown below.

cyberithub@macos1066 ~ % git pull

Finally add all the changes prior to git stash using git stash pop command as shown below and see if it indeed solves "error: Pulling is not possible because you have unmerged files" in your system.

cyberithub@macos1066 ~ % git stash pop

 

Solution 5: Automatically rebase changes

Last solution that may work best for you is that you can automatically rebase all your changes on the pulled version using git pull --autostash command and then check if it solves your "error: Pulling is not possible because you have unmerged files"

cyberithub@macos1066 ~ % git pull --autostash

Leave a Comment