Error pull is not possible because you have unmerged files

Do you get the error message, "Pulling is not possible because you have unmerged files," when you try to git pull changes? Worry no more.

Do you get the error message, «Pulling is not possible because you have unmerged files,» when you try to git pull changes? Worry no more.

This tutorial explains the origin of the error message and how to solve it.

Let’s do this!

Understand the basics

Git pull

Let’s start by understanding what git pull entails.

Think of the code tracking environment as a two-part architecture: local and remote environment. In a local environment, we create the project files in a working directory. Next, we stage the changes. We can fall back to untracked files or safely store the files in a repository.

In simple terms, a repository is the version control system’s database. Here, Git refers to the new changes as commits and assigns them unique numbers called commit hashes.

Although the changes are safely stored and can be retrieved, they are local. That means a loss of the computer results in a loss of our files. So, we send the changes to a remote repository through git push.

ALSO READ: git show explained in-depth [Practical Examples]

We can then collaborate with more remote developers, working on the same or separate git branches.  A developer does their part and pushes the changes to the specified branch. To get the other developer’s changes, you do the opposite of git push: git pull.

git pull is the process of updating a local repository with its updated remote version.

Some articles related to this topic:
git pull force Explained
git pull command examples
git pull vs git pull —rebase explained with examples

Git merge

A typical repository has multiple branches: the main branch and its subbranches.

After creating commits in the subbranch, we unite them with the main branch. This process is called git merge. Git merge enables collaboration in a project. Git is intelligent enough to notice the merge timestamps per branch.

Some articles related to this topic:
git merge explained
Git merge vs rebase and the problems they solve

However, here is a catch.

Merge Conflicts

Sometimes Git gets confused when it cannot determine the logical hierarchy of code portions resulting from commits of separate branches. Such a scenario is called a merge conflict.

A merge conflict needs to be resolved. Otherwise, your subsequent pull requests will fail. You can correct the pull error by resolving the merge conflict through a hard reset or manually accepting the new commit’s changes in the script file.

Now that you know the origin and the solution to the typical error, «Pulling is not possible because you have unmerged files,» let’s set up a lab environment and do it practically.

ALSO READ: Git create repository

Lab environment setup

Log into your GitHub account and create a new repo with a README.md file. I am creating one called lab.

[SOLVED] Pulling is not possible because you have unmerged files

Copy the repo URL.

[SOLVED] Pulling is not possible because you have unmerged files

Return to your local machine’s terminal, clone the repo, and cd into it.

[SOLVED] Pulling is not possible because you have unmerged files

Now let’s generate the error: Pulling is not possible because you have unmerged files.

Generate the error: Pulling is not possible because you have unmerged files

Make a commit in the main branch

Let’s create index.html with a title and a description paragraph.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Pulling is not possible because you have unmerged files</title>
</head>
<body>
    <h2>Let's create the error</h2>
    <p>You are about encounter the error: pulling is not possible because you have unmerged files</p>
</body>
</html>

Stage and commit the changes.

git add index.html
git commit -m "Add index.html"

Now we have two commits in the main branch.

git log --oneline

[SOLVED] Pulling is not possible because you have unmerged files

Make a commit in the feature branch

Create a feature branch.

git switch -c feature_branch

And modify the index.html file by adding a paragraph: First, create the feature branch. We use Visual Studio Code to ease the development and manual error correction. Stage the changes and make a commit.

Now the feature branch is ahead of the main branch with a commit.

ALSO READ: git detached HEAD Explained [Easy Examples]

[SOLVED] Pulling is not possible because you have unmerged files

Switch to the main branch, and modify the index.html with a paragraph: Generating the error.

Next, stage the changes and create a commit.

[SOLVED] Pulling is not possible because you have unmerged files

What happens when we attempt to merge the feature branch?

Let’s find out.

Create a merge conflict

Now let’s attempt merging the feature branch’s changes.

Input

git merge feature_branch

Output

user@hostname:~/lab$ git merge feature_branch 
Auto-merging index.html
CONFLICT (content): Merge conflict in index.html
Automatic merge failed; fix conflicts and then commit the result.

Git tells us it found a conflict in the index.html file and recommends that we correct the error before proceeding.

Okay, let’s inspect the file.

Input

cat index.html

Output

user@hostname:~/lab$ cat index.html 
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Pulling is not possible because you have unmerged files</title>
</head>
<body>
    <h2>Let's create the error</h2>
    <p>You are about encounter the error: pulling is not possible because you have unmerged files</p>
<<<<<<< HEAD
    <p>Generating the error</p>
=======
    <p>First, create the feature branch</p>
>>>>>>> feature_branch
</body>

Git is stranded on whether the paragraph from the latest commit (HEAD) from the main branch should come first or the feature branch’s paragraph.

<<<<<<< HEAD
    <p>Generating the error</p>
=======
    <p>First, create the feature branch</p>
>>>>>>> feature_branch

We could edit the file to capture our intention before merging the feature branch. However, let’s ignore the call to resolve the conflict. Nor merge the feature branch.

ALSO READ: First Time Git Setup | Git Config Global

Instead, let’s return to the GitHub repository and update the README.md file

[SOLVED] Pulling is not possible because you have unmerged files

Getting error

Now attempt to pull the remote changes.

Input

git pull

Output

user@hostname:~/lab$ git pull
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.

Git says we have an error: Pulling is not possible because you have unmerged files.

Pulling is not possible because you have unmerged files

Resolving the error: Pulling is not possible because you have unmerged files

Although we could reset one of the commits, we will retain the changes by accepting both paragraphs in the index.html.

from

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Pulling is not possible because you have unmerged files</title>
</head>
<body>
    <h2>Let's create the error</h2>
    <p>You are about encounter the error: pulling is not possible because you have unmerged files</p>
<<<<<<< HEAD
    <p>Generating the error</p>
=======
    <p>First, create the feature branch</p>
>>>>>>> feature_branch
</body>
</html>

to

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Pulling is not possible because you have unmerged files</title>
</head>
<body>
    <h2>Let's create the error</h2>
    <p>You are about encounter the error: pulling is not possible because you have unmerged files</p>
    <p>Generating the error</p>
    <p>First, create the feature branch</p>
</body>
</html>

Then, stage and commit the changes.

ALSO READ: Git merge vs rebase and the problems they solve

Input

git add .
git commit -m "Accept both paragraphs"

Output

user@hostname:~/lab$ git add .
user@hostname:~/lab$ git commit -m "Accept both paragraphs"
[main 308f222] Accept both paragraphs

Now git pulling does not produce the primary error.

Input

git pull

Output

user@hostname:~/lab$ git pull
remote: Enumerating objects: 5, done.
remote: Counting objects: 100% (5/5), done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (3/3), 779 bytes | 194.00 KiB/s, done.
From github.com:Stevealila/lab
   634d087..4685287  main       -> origin/main
hint: You have divergent branches and need to specify how to reconcile them.
hint: You can do so by running one of the following commands sometime before
hint: your next pull:
hint: 
hint:   git config pull.rebase false  # merge
hint:   git config pull.rebase true   # rebase
hint:   git config pull.ff only       # fast-forward only
hint: 
hint: You can replace "git config" with "git config --global" to set a default
hint: preference for all repositories. You can also pass --rebase, --no-rebase,
hint: or --ff-only on the command line to override the configured default per
hint: invocation.
fatal: Need to specify how to reconcile divergent branches.

Although the pull process goes through, we get some warnings. The relieving part is that Git gives us some hints on how to get rid of the warnings.

[SOLVED] Pulling is not possible because you have unmerged files

Summary

The error, «Pulling is not possible because you have unmerged files,» often results from attempting to git pull changes without resolving local merge conflicts. As shown in this tutorial, you can correct the conflicts before proceeding with git pull.

ALSO READ: git fetch vs git pull Explained [With Examples]

Why error pulling not possible because of unmerged files is happeningThe Git error that throws error: pulling is not possible because you have unmerged files. occurs during file operations in Git. But there are other error messages like this – pulling is not possible error.

So, if you are reading this article, you are in the right place for not only fixing this error but its related error messages as well.

Contents

  • Why Error: Pulling Not Possible Because of Unmerged Files Is Happening?
    • – Conflict During Merging of Files
    • – Steps To Reproduce the Conflict Error
    • – Assessing the Conflict Error Message
    • – Ignore the Conflict Error Message
  • How To Fix Pulling Is Not Possible Error?
    • – Remove Changes With Git Reset –Hard
    • – Keep the Changes by Manual Editing
    • – Stash the Changes for Later
  • Conclusion

You can not pull because of unmerged files due to a conflict during the merging of files. Below are listed the common errors and the main reasons they can happen.

– Conflict During Merging of Files

You’ll get a merge conflict when you try to merge two copies of the same file with different contents. This can occur when working with other team members on a large project. You might think it’s an error on your part. However, an investigation may reveal another team member made some changes that you do not know.

Let’s reproduce the error step-by-step to detect at what point the error occurs.

– Steps To Reproduce the Conflict Error

The following steps are a series of Git events that you can carry out on the command line. Check the example below that reproduces the “pulling is not possible” error:

  • Create a sample folder. You can name the folder “test”.
  • Create a folder called RepoA in the folder
    • Initiate a new repository.
    • Create a file called FileRepoA.
    • Add FileRepoA to the Git History using the git add command.
    • Write a commit message for the addition of FileRepoA.
  • Clone RepoA to a new repository called RepoB. So, RepoA and RepoB now have the same structure and content.
    • Modify FileRepoA in RepoB with a text that reads text2
    • Add the file to Git’s history with the git add command
    • Write a git commit message for the change
  • Switch back to RepoA
    • Modify FileRepoA with a text that reads text1
    • Add FileRepoA in RepoA to the Git history
    • Write a commit message for the change
  • Switch back to RepoB
    • Execute a git pull. You’ll get an error message about merge conflicts

– Assessing the Conflict Error Message

From the previous section, the last action resulted in an error message. And the following snippet is an excerpt of the error message:

Auto-merging file
CONFLICT (content): Merge conflict in file
Automatic merge failed; fix conflicts and then commit the result.

From the error messages, Git gave a detailed explanation of what went wrong. Some of this information indicates there is a failure in an automatic merge. As a result, Git advises that you fix the conflict and commit your result.

Nevertheless, if you continue without fixing the conflict, you’ll run into an error.

For example, at the current state of the RepoB, an attempt to run git checkout results in an error. The following is an excerpt of the error:

RepoB $ git checkout
error: you need to resolve your current index first
FileRepoA: needs merge

At this stage, do not add FileRepoA to the Git history. If you do, you’ll get an error that reads “error: you have not concluded your merge (MERGE_HEAD exists).”. What’s more, if you are using Laravel forge, you can replicate what we’ve done on your server.

However, you’ll need to look online for “forge your site has unmerged files on the server” help articles.

You should continue reading further. We’ll teach you how to fix it! In the next section, let’s ignore the conflict and see what happens.

– Ignore the Conflict Error Message

When you ignore the conflict message, you’ll still get an error when you try to pull in some changes. Let’s ignore the error and make another modification to FileRepoA in RepoA. After that, we’ll commit our changes, and switch back to RepoB.

RepoA $ echo “text1” >> FileRepoA && git add file && git commit -m “msg” && cd ../RepoB

Meanwhile, in RepoB we’ll attempt to pull in the changes from RepoA. However, we get the following error:

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.

In the above-mentioned warning message, there is a suggestion that you should make some changes to the work tree using the git add command. Moreover, the error message also means a file in RepoB is unmerged. So, you can confirm this with the git status command.

$ git status
On branch master
Your branch and ‘origin/master’ have diverged,
and have 1 and 1 different commits each, respectively.
(use “git pull” to merge the remote branch into yours)

< We’ve truncated part of the output >

Read further sections where we’ll explain in detail how you can fix the error.

How To Fix Pulling Is Not Possible Error?

You can fix the “pulling is not possible” error by performing the following actions:

  • Throw away the changes with git reset –hard
  • Keep the changes by manual editing
  • Stash the changes for later

– Remove Changes With Git Reset –Hard

You can remove all the changes you’ve made in a branch with git reset –hard origin command. In our case, this means we can execute “git reset –hard origin” in RepoB to fix the conflict. But be aware that the reset command will delete our current changes. Still, after the hard reset, that does not mean pulling will be successful.

The following are the complete steps to take to complete the hard reset and fix the conflict.

  • In RepoB, execute the command: git reset –hard origin
  • Use git add on the file
  • Pull from RepoA

When you do the above-listed steps, RepoA and RepoB will be the same. So, you can continue with your work.

– Keep the Changes by Manual Editing

Keeping the changes that you’ve made is another option to fix a conflict when merging files. This means you can edit one of the conflicting files in an editor. Based on our sample repository for this article, we can do the following:

  • Open the file in RepoB in an editor
  • Edit the file’s content to match that of RepoA
  • Use git add on the file
  • Pull the changes from RepoA

Once you repeat the above steps, you’ll no longer receive any pulling error. As a result, you can continue with your Git tasks. If you are working on a team and conflict occurs, you can do manual editing with your teammates. Afterward, you can pull in the changes before you commit other code to the branch or repository.

– Stash the Changes for Later

Another option to fix the pulling error is to utilize the stashing ability of Git. So, we are certain you are reading this article because one of your searches led you here. An example string in the line of pulling is not possible because you have unmerged files. git stash.

In your repo, you can stash the changes you’ve made to a branch before pulling an update from another branch. Git will save your changes in a dedicated folder, and you can use those changes at a later time. This means that in our sample repository, we can use stashing to fix the conflicts, but an error will occur if you try to pull some changes immediately after stashing.

Such an error will tell you to fix the conflict in the work tree. Therefore, the following is the right way to fix the conflict between RepoA and RepoB:

  • Add the changed file in RepoB to the Git history.
  • Execute the stash command.
    • This will display a message that Git saved your changes.
  • Edit the file in RepoB to match that of RepoA
  • Try to pull the changes from RepoA

At this stage, you’ll get the following error:

error: your local changes to the following files would be overwritten by merge:

From the commit message, it’s obvious that you need to commit your changes before you can merge. So, continue with the following steps:

  • Use the git add command to add the file to Git’s history
  • Commit the changes, and write a commit message
  • Pull the changes from FileRepoA

You’ll get a sample message like:

Merge made by the ‘ort’ strategy.

Conclusion

This article explained how to fix the pulling not possible error. We showed you how to replicate the error to find out when it occurs and how to fix it. The following list is the summary of the most important points of the article:

  • A conflict arises in Git when you try to merge files with the same name but different contents.
  • To fix the “pulling is not possible” error, you can use git reset –hard.
  • Always write a commit message after adding a file to Git’s history.
  • Ensure your files are updated to avoid conflict when pulling changes.
  • You need to commit your changes or stash them before you can merge.

How to fix pulling is not possible errorAt this stage, you have what it takes to fix the “pulling is not possible” error message.

  • Author
  • Recent Posts

Position is Everything

Position Is Everything: Your Go-To Resource for Learn & Build: CSS,JavaScript,HTML,PHP,C++ and MYSQL.

Position is Everything

Git is a distributed version control system with C language development. Version control system can keep a history of files, and can roll back files to another state using history.

Git and Github include some very cool features. Here I am going to share solution of one of the issues you ever get if you have used GitHub.

It is very common issue you might get while using Github and issue is listed below:

Pull is not possible because you have unmerged files.

Please, fix them up in the working tree, and then use ‘git add/rm <file>’

as appropriate to mark resolution or use ‘git commit -a’.

This issue might occur if you have changes in same files or same line of the file.So GitHub is not allowing to pull changed before you merge its index.

Firstly, I don’t understand what is this issue so I searched this issue in google and every site where I get solution and everyone is saying to commit files or remove uncommitted files to pull files from server.
But it is not possible because I want to keep changes and also want to get changes from the server.

Git has three working areas, namely: the working directory (Working Directory), the staging area (Stage or Index) and repository (Repository or Git Directory).

So as the solution of the above issue what I did is, Add the file to Github using git add command because I don’t want to commit local changes to pull changes from server and technically it is not necessary too.
Let’s check the command:

git add filename

git stash

git pull

git stash pop

The git adds command adds a change in the working directory to the staging area, then, change the status Staged state.it was placed Git staging area.Git adds command will inform Git that you have changes in the same file and will include updates to a particular file in the next commit.

Git add command not affect the repository in any way,It just add file contents to the index so changes in the files are not recorded until you run git commit command so it is the safest way or solution you can do when you get above error.

Here, I am done with my article and hope this solution is useful to you and clear your mind, let me know if you have any suggestion/comments/questions on this trick/article.

в настоящее время происходит то, что у вас есть определенный набор файлов, которые вы пытались объединить ранее, но они вызвали конфликты слияния.
В идеале, если вы получаете конфликт слияния, он должен разрешить их вручную и зафиксировать изменения с помощью git add file.name && git commit -m "removed merge conflicts".
Теперь другой пользователь обновил файлы, о которых идет речь, в своем репозитории и подтолкнул свои изменения к общему восходящему РЕПО.

бывает так, что ваши конфликты слияния из (возможно) последнего коммита не были не решено, так что ваши файлы не объединены все в порядке, и, следовательно,U(unmerged флаг) для файлов.
Так что теперь, когда вы делаете git pull, git выдает ошибку, потому что у вас есть какая-то версия файла, которая не правильно решена.

чтобы решить эту проблему, вам нужно будет разрешить конфликты слияния, о которых идет речь, а также добавить и зафиксировать изменения, прежде чем вы сможете сделать git pull.

воспроизведение образца и разрешение вопрос:

# Note: commands below in format `CUURENT_WORKING_DIRECTORY $ command params`
Desktop $ cd test

во-первых, давайте создадим структуру репозитория

test $ mkdir repo && cd repo && git init && touch file && git add file && git commit -m "msg"
repo $ cd .. && git clone repo repo_clone && cd repo_clone
repo_clone $ echo "text2" >> file && git add file && git commit -m "msg" && cd ../repo
repo $ echo "text1" >> file && git add file && git commit -m "msg" && cd ../repo_clone

теперь мы находимся в repo_clone, и если вы делаете git pull, это вызовет конфликты

repo_clone $ git pull origin master
remote: Counting objects: 5, done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
From /home/anshulgoyal/Desktop/test/test/repo
 * branch            master     -> FETCH_HEAD
   24d5b2e..1a1aa70  master     -> origin/master
Auto-merging file
CONFLICT (content): Merge conflict in file
Automatic merge failed; fix conflicts and then commit the result.

если мы проигнорируем конфликты в Клоне и сделаем больше коммитов в исходном РЕПО сейчас,

repo_clone $ cd ../repo
repo $ echo "text1" >> file && git add file && git commit -m "msg" && cd ../repo_clone

а то git pull, мы получим

repo_clone $ git pull
U   file
Pull is not possible because you have unmerged files.
Please, fix them up in the work tree, and then use 'git add/rm <file>'
as appropriate to mark resolution, or use 'git commit -a'.

отметим, что file теперь находится в несвязанном состоянии, и если мы сделаем git status, мы можем ясно видеть то же самое:

repo_clone $ git status
On branch master
Your branch and 'origin/master' have diverged,
and have 1 and 1 different commit each, respectively.
  (use "git pull" to merge the remote branch into yours)

You have unmerged paths.
  (fix conflicts and run "git commit")

Unmerged paths:
  (use "git add <file>..." to mark resolution)

        both modified:      file

Итак, чтобы решить эту проблему, нам сначала нужно решить конфликт слияния, который мы проигнорировали ранее

repo_clone $ vi file

и установите его содержимое в

text2
text1
text1

а затем добавить его и зафиксировать изменения

repo_clone $ git add file && git commit -m "resolved merge conflicts"
[master 39c3ba1] resolved merge conflicts

Понравилась статья? Поделить с друзьями:
  • Error public symbol defined in both module
  • Error reading pak file error 0x00000017 apex
  • Error reading pak file apex legends
  • Error reading mbr victoria hdd
  • Error reading machine specific preferences they will be reset to defaults что делать