Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git stuck on master | MERGING

Tags:

git

There are two remotes assigned, origin is used to pull the changes and harmeet is the production.

I tried git reset --hard but as soon as I pull latest changes the status reverts to master | MERGING and then I can't push latest code to harmeet because Git tells me everything is up to date. I am not sure what is wrong here.

Git Status

like image 886
AspiringCanadian Avatar asked Oct 05 '16 16:10

AspiringCanadian


1 Answers

As mentioned in @Holger's comment, you can do git merge --abort to abort the merge. However, you might not want to do that. The merge happens because the remote (origin) has changes that you don't have locally. Your history might look something like this:

*--*--A--B--C [master, harmeet/master]
       \
        D--E [origin/master]

(Note that master == harmeet/master. I'll come to that in a minute.)

There are three solutions: merge, rebase, or force update.

Merge

The easiest solution would be to just complete the merge. To do so, resolve any conflicts in your editor, stage with git add ., and commit with git commit. Your history would then look like this:

*--*--A--B---C [harmeet/master]
       \      \
        \      F [master]
         \    /
          D--E [origin/master]

and then you can git push origin master to update origin and git push harmeet master to update harmeet.

Rebase

If you want to keep a linear history, abort the merge and then do:

git pull --rebase

(If there are any conflicts, resolve them and continue with git rebase --continue.)

Your history would then look like this:

*--*--A--B--C [harmeet/master]
       \
        D--E [origin/master]
            \
             B'--C' [master]

You can then update origin with:

git push origin master

and force-update harmeet with:

git push --force-with-lease harmeet master

Your final history would then be:

*--*--A--D--E--B'--C' [master, origin/master, harmeet/master]

Force-update

If you really don't want the changes from origin, you can do:

git push --force-with-lease origin master

and your history would look like this:

*--*--A--B--C [master, harmeet/master, origin/master]

If Git tells you that harmeet/master is up-to-date, then it is at the same commit as your local master, unless someone has pushed to harmeet/master since your last fetch.

If your goal is to get the changes from origin (commits D and E) to harmeet, then you'll need to either rebase or merge, and then push, as described above.

like image 103
Scott Weldon Avatar answered Oct 06 '22 21:10

Scott Weldon