I forgot to git pull
my code before editing it; when I committed the new code and tried to push, I got the error «push is not possible».
At that point I did a git pull
which made some files with conflict highlighted. I removed the conflicts but I don’t know what to do from here.
I tried to git commit
again but it says the «commit is not possible because you have unmerged files»:
error: Committing is not possible because you have unmerged files.
pkamb
32.3k22 gold badges158 silver badges186 bronze badges
asked Oct 18, 2012 at 18:54
1
If you have fixed the conflicts you need to add the files to the stage with git add [filename]
, then commit as normal.
answered Oct 18, 2012 at 18:57
jonnystotenjonnystoten
6,9852 gold badges31 silver badges36 bronze badges
7
You need to do two things.
First add the changes with
git add .
git stash
git checkout <some branch>
It should solve your issue as it solved to me.
answered Mar 16, 2015 at 15:57
5
You can use git stash
to save the current repository before doing the commit you want to make (after merging the changes from the upstream repo with git stash pop
). I had to do this yesterday when I had the same problem.
answered Oct 20, 2012 at 1:49
mumanmuman
1417 bronze badges
This error occurs when you resolve the conflicts but the file still needs to be added in the stage area. git add . would solve it. Then, try to commit and merge.
greg-449
108k230 gold badges104 silver badges144 bronze badges
answered Jul 9, 2019 at 6:08
Since git 2.23 (August 2019) you now have a shortcut to do that: git restore --staged [filepath]
.
With this command, you could ignore a conflicted file without needing to add and remove that.
Example:
> git status
...
Unmerged paths:
(use "git add <file>..." to mark resolution)
both modified: file.ex
> git restore --staged file.ex
> git status
...
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: file.ex
answered Apr 23, 2020 at 11:20
macabeusmacabeus
3,9393 gold badges37 silver badges61 bronze badges
2
I’ve had a similar issue which boiled down to removing files under «unmerged paths»
Those files had to be removed using git rm
answered Jul 4, 2019 at 11:01
Yann VRYann VR
4765 silver badges8 bronze badges
So from the error above. All you have to do to fix this issue is to revert your code. (git revert HEAD
) then git pull
and then redo your changes, then git pull
again and was able to commit or merge with no errors.
Brydenr
7981 gold badge21 silver badges30 bronze badges
answered Dec 17, 2019 at 17:27
appdesignsappdesigns
1141 silver badge10 bronze badges
Merge Conflicts arise when multiple agents modify the same part of a file and push their changes to a remote branch. When you attempt to merge, pull from or push to these branches — there’s a conflict, and Git isn’t sure which set of changes to accept and which to reject, since there’s no objective measure of which change is right.
Merge Conflicts only arise when it’s impossible to discern upfront which changes to keep, and in this case, you have to step in and make a decision.
There are three ways you can deal with a Merge Conflict — you can continue with the merge, by updating your local file to match what already exists in a remote repository, you can abort a merge, which is typically done if there’s a major conflict that isn’t easily remedied or you can keep the local changes from the working directory and force them upon the remote repository.
In this guide, we’ll take a look at the three ways you can resolve a Merge Conflict with Git.
How do Merge Conflicts Happen?
Let’s quickly create a repository and a merge conflict so we can observe which changes caused it and how the files look like when we resolve it. We’ll emulate a remote-work environment by creating two folders and two Git repositories within them:
$ cd Jane
$ git init
$ git remote add origin https://github.com/DavidLandup0/solving-merge-conflicts.git
$ cd..
$ cd John
$ git init
$ git remote add origin https://github.com/DavidLandup0/solving-merge-conflicts.git
Jane and John are working on a project together, and share the same file — README.md
. John wrote the file, accidentally leaving in a typo, and pushed it to the remote origin. Jane caught this, fixed the typo and pushed the file to the remote origin again.
Once John wanted to add a new line to the file, and merge his branch to the main
branch — his README.md
(which has the typo) was in conflict with the main
‘s README.md
, which had the typo fixed.
On John’s feature branch, he added a README.md
file:
$ git branch feature_john
$ git checkout feature_john
Switched to branch 'feature_john'
$ echo 'Welcome to our READMW.md!' >> README.md
$ git add README.md
$ git commit -m "Added README.md"
[feature_john c44d65f] Added README.md
1 file changed, 1 insertion(+)
create mode 100644 README.md
$ git push origin feature_john
git push origin feature_john
Enumerating objects: 4, done.
Counting objects: 100% (4/4), done.
...
To https://github.com/DavidLandup0/solving-merge-conflicts.git
* [new branch] feature_john -> feature_john
$ git checkout main
Switched to branch 'main'
$ git merge feature_john
Updating 48f09c2..c44d65f
Fast-forward
README.md | 1 +
1 file changed, 1 insertion(+)
create mode 100644 README.md
$ git push origin main
Total 0 (delta 0), reused 0 (delta 0), pack-reused 0
To https://github.com/DavidLandup0/solving-merge-conflicts.git
48f09c2..c44d65f main -> main
John added a new file to his branch and pushed it to his remote branch and then merged into main
— no issues, there weren’t any files there before that.
Now, Jane wants to get up to date with the main
branch by pulling the changes made there, notices the typo — fixes it, and pushes back to main to prevent others from pulling the erroneous piece:
$ cd Jane
$ git pull origin main
remote: Enumerating objects: 4, done.
remote: Counting objects: 100% (4/4), done.
...
Updating 48f09c2..c44d65f
Fast-forward
README.md | 1 +
1 file changed, 1 insertion(+)
create mode 100644 README.md
$ git branch feature_jane
$ git checkout feature_jane
$ echo 'Welcome to our README.md!' > README.md
$ git add README.md
$ git commit -m "Fixed typo in README.md file"
[feature_jane 60f64fc] Fixed typo in README.md file
1 file changed, 1 insertion(+), 1 deletion(-)
$ git push origin feature_jane
Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Writing objects: 100% (3/3), 292 bytes | 292.00 KiB/s, done.
...
To https://github.com/DavidLandup0/solving-merge-conflicts.git
* [new branch] feature_jane -> feature_jane
$ git checkout main
Switched to branch 'main'
$ git merge feature_jane
Updating c44d65f..60f64fc
Fast-forward
README.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
$ git push origin main
Total 0 (delta 0), reused 0 (delta 0), pack-reused 0
To https://github.com/DavidLandup0/solving-merge-conflicts.git
c44d65f..60f64fc main -> main
Now main
is clean — no typo in the README.md
. Though, John’s file is now out of sync.
- If he tries pulling the origin’s
main
— a Merge Conflict will occur. - If he tries to push a change with a conflicting change on the remote branch — a Merge Conflict will occur.
- If he tries to run
$ git merge
on two branches that have conflicting changes — a Merge Conflict will occur.
Say John added a new line to the file, pulled from the main
branch and then tried merging his new addition into main
before pushing his :
$ echo 'New line!' >> README.md
$ git add README.md
$ git commit -m "Added new line to README.md"
[feature_john ba27684] Added new line to README.md
1 file changed, 1 insertion(+)
$ git checkout main
Switched to branch 'main'
$ git pull origin main
From https://github.com/DavidLandup0/solving-merge-conflicts
* branch main -> FETCH_HEAD
Updating c44d65f..60f64fc
Fast-forward
README.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
$ git merge feature_john
Auto-merging README.md
CONFLICT (content): Merge conflict in README.md
Automatic merge failed; fix conflicts and then commit the result.
There it is — Merge conflict in README.md
. There are three things John can do to solve this conflict, as he is now in the MERGING phase. When Git encounters a conflict, it doesn’t abandon the merge — it allows you to attempt fixing the issue on the spot or abandon it if you’d like to.
Find Merge Conflict Source
The first step you need to take is find out why there’s a Merge Conflict in the first place. When in the MERGING phase, as we are, Git will annotate the file that’s causing the conflict. If we open the README.md
file on John’s local machine, we’ll see:
<<<<<<< HEAD
Welcome to our README.md!
=======
'Welcome to our READMW.md!'
New line!
>>>>>>> feature_john
The <<<<<<<
denotes the cause of the conflict and the current reference follows it (HEAD
). This is the change from main
. Then, we’ve got the =======
line (just a separator) before John’s set of changes.
Check out our hands-on, practical guide to learning Git, with best-practices, industry-accepted standards, and included cheat sheet. Stop Googling Git commands and actually learn it!
Finally, the >>>>>>>
denotes that that’s the end of the conflict, with the branch name we’re trying to merge into the top side of =======
.
Note: If we were merging by pulling main
changes into feature_john
— the order of changes would be the opposite, since the current reference would be on feature_john
and the changes on main
would be beneath the =======
line. Though, keep in mind that this isn’t good practice as the feature branch is meant to contain separate changes from the main branch.
Solve Merge Conflict with git merge —abort
A valid way to solve the conflict is to abort from it — and stop the MERGING phase. This is typically done when the solution isn’t to fix a single line — and when large changes need to be made. This usually necessitates a plan with a team member as well.
If we abort the merge, the added conflict lines will be removed and we’ll have John’s
README.md
file once again.
While we’re still in the merging phase, let’s abort the merge altogether:
$ git merge --abort
This simply aborts the merge and your file is returned to its state before you’ve encountered the conflict:
'Welcome to our READMW.md!'
New line!
If you’re using Git’s Command-Line Editor (or other shells that support the feature), you’ll also be able to see which phase you’re in:
(main)
$ git merge feature_john
Auto-merging README.md
CONFLICT (content): Merge conflict in README.md
Automatic merge failed; fix conflicts and then commit the result.
(main|MERGING)
$ git merge --abort
(main)
$
Now, with your file out of harm’s way — phone your colleague and discuss your next steps. Alternatively, if you accept their changes, you can continue with the merge.
Solve Merge Conflict with git merge —continue
You can continue the merge with a conflict, but Git won’t overwrite the files automatically. If you try merging, encounter a conflict, and try to $ git merge --continue
, you’ll face another error:
$ git merge feature_john
Auto-merging README.md
CONFLICT (content): Merge conflict in README.md
Automatic merge failed; fix conflicts and then commit the result.
$ git merge --continue
error: Committing 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.
U README.md
If it were possible to continue, Git would’ve continued already. You’re still in the MERGING phase, so you can change your README.md
to conform to main
‘s version of it, mark the resolution by adding or removing the file again, and then run the $ git merge --continue
command.
Let’s fix the file first. In our case, since the «Welcome…» line was causing an issue, but the «New line!» wasn’t — we can leave the new line in — John’s new feature — and fix the typo that’s in conflict:
Welcome to our README.md!
New line!
Now, we add
the file once again and run the $ git merge --continue
command:
Fix the file...
$ git add README.md
$ git merge --continue
[main fea8fbb] Merge branch 'feature_john'
You’ve accepted the changes from main
and adapted your local file to reflect it, and adding it back.
Note: In newer versions of Git, when you run the $ git merge --continue
command, it’ll commit that merge automatically, so you don’t have to, though, you do have to add the changed file again. When you run the command, a text editor will open up with the default commit message of Merge branch 'branch_name'
. You can just exit it, saving the message, to commit the change and merge the branches.
Solve Merge Conflict By Forcing Local Changes to Remote
Instead of aborting, or yielding to changes — if you’re certain that the changes made in your working directory are certainly the ones to keep, you can keep the local changes instead of adapting to the remote ones.
When a Merge Conflict occurs, you can $ git checkout
the file from feature_john
, and then add it to the main
branch.
Note: Remember that $ git checkout
updates the files in the working tree to match the version in the index.
When updating — you can keep the changes made on a different branch and apply it to this branch. On the main
branch, into which we wish to merge feature_john
, let’s update the README.md
file to contain the changes from the feature_john
branch.
In the context of main
, these changes are referred to as theirs, while the changes on main
are referred to as ours. If you wish to keep changes from main
, switch the --theirs
flag with --ours
:
$ git checkout --theirs README.md
Updated 1 path from the index
$ git add README.md
$ git commit -m "Accepting changes from feature_john"
[main 5541f29] Accepting changes from feature_john
Now, you can merge the rest of the changes that are not in conflict cleanly, since we’ve only created a roundabout merge for the one file that caused a conflict this way.
Conclusion
In this guide, we’ve taken a look at how to resolve Merge Conflicts in Git. We’ve explored the three ways you can bump into this common error, and how they arise.
Then, we’ve explored three solutions to the issue, with the dummy two local repositories and a remote repository we’ve created in the examples.
git merges branches, git merges branches, git merges branches, git merges branches, git merges branches, git merges branches, git merges branches, git merges branches, git merges branches, git merges branches, git merges branches, git merges branches, git merges branches, git merges branches, git merges branches, git merges branches, git merges branches, git merges branches, git merges branches
When I was doing project work, my colleague modified a CPP code, and I also modified the code. The two codes clashed. After submission, his code git merged automatically and was prompted: [master| MERGEING]
$ git merge my_new_branch
error: Merging 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.
or error:
Auto-merging src/ui/menu/wizardGroup.c
Auto-merging src/ui/menu/drawmenu5.c
Auto-merging src/ui/menu/drawmenu3.c
Auto-merging src/ui/menu/drawmenu2.c
Auto-merging src/ui/menu/drawmenu1.c
Auto-merging src/ui/menu/drawmenu0.c
Auto-merging src/string/language_d.h
CONFLICT (content): Merge conflict in src/string/language_d.h
Auto-merging src/string/languageDict.h
CONFLICT (content): Merge conflict in src/string/languageDict.h
Auto-merging src/drawui.c
Auto-merging src/dev/dev_phascan.c
Auto-merging src/dev/dev_flexscan.c
Auto-merging src/callback.c
Automatic merge failed; fix conflicts and then commit the result.
* solution:
If you have fixed the files you need to add the files to the stage with git add [filename], then commit as normal. Git add [modified conflicting files], and finally, commit the conflicting issues as normal: git commit [modified conflicting files] -m “comment content”
* is simply:
- use git diff or git status to check which files are in conflict, the conflict will prompt:
++< < < < < < < HEAD
++< < < < < < < new_branch
-
modify your conflicting files, after the modification, save.
-
use git add XXX and add all the files you have modified.
-
finally, with git commit-a-m “note information” commit, complete.
Read 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: 10 ways to delete file or directory effortlessly in GIT
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: How to PROPERLY list remote branches in git
Lab environment setup
Log into your GitHub account and create a new repo with a README.md
file. I am creating one called lab
.
Copy the repo URL.
Return to your local machine’s terminal, clone the repo, and cd
into it.
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
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 fetch vs git pull Explained [With Examples]
Switch to the main branch, and modify the index.html
with a paragraph: Generating the error.
Next, stage the changes and create a commit
.
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: git blame explained in layman’s terms [Practical Examples]
Instead, let’s return to the GitHub repository and update the README.md
file
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.
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 undo commit PROPERLY [5 Different Ways]
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.
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 pull force Explained [Easy Examples]
The 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.
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.
At this stage, you have what it takes to fix the “pulling is not possible” error message.
- Author
- Recent Posts
Position Is Everything: Your Go-To Resource for Learn & Build: CSS,JavaScript,HTML,PHP,C++ and MYSQL.
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 dont 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.
The error message:
merge: remote/master – not something we can merge
is saying that Git doesnt recognize remote/master
. This is probably because you dont 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.
Git merge is not possible because I have unmerged files
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>
Related posts on Git :
- git flow – Gitflow feature vs bugfix branch naming
- git – Alternatives to GitHub Pages?
- confusion about git rev-list
- git – What does the checkout step in circle ci do?
- What is the difference between IntelliJs Shelve and Git stash?
- git – destination path already exists and is not an empty directory
- git – fatal: This operation must be run in a work tree
- git – Push rejected, failed to compile Node.js app heroku
- git – SourceTree keeps asking for Github password