Your branch is ahead of 'origin/master' by 3 commits

GitGit Rebase

Git Problem Overview


I am getting the following when running git status

Your branch is ahead of 'origin/master' by 3 commits.

I have read on some other post the way to fix this is run git pull --rebase but what exactly is rebase, will I lose data or is this simple way to sync with master?

Git Solutions


Solution 1 - Git

You get that message because you made changes in your local master and you didn't push them to remote. You have several ways to "solve" it and it normally depends on how your workflow looks like:

  • In a good workflow your remote copy of master should be the good one while your local copy of master is just a copy of the one in remote. Using this workflow you'll never get this message again.
  • If you work in another way and your local changes should be pushed then just git push origin assuming origin is your remote
  • If your local changes are bad then just remove them or reset your local master to the state on remote git reset --hard origin/master

Solution 2 - Git

Use these 4 simple commands

Step 1 : git checkout <branch_name>

This is obvious to go into that branch.

Step 2 : git pull -s recursive -X theirs

Take remote branch changes and replace with their changes if conflict arise. Here if you do git status you will get something like this your branch is ahead of 'origin/master' by 3 commits.

Step 3 : git reset --hard origin/<branch_name>

Step 4 : git fetch

Hard reset your branch.

Enjoy.

Solution 3 - Git

There is nothing to fix. You simply have made 3 commits and haven't moved them to the remote branch yet. There are several options, depending on what you want to do:

  • git push: move your changes to the remote (this might get rejected if there are already other changes on the remote)
  • do nothing and keep coding, sync another day
  • git pull: get the changes (if any) from the remote and merge them into your changes
  • git pull --rebase: as above, but try to redo your commits on top of the remote changes

You are in a classical situation (although usually you wouldn't commit a lot on master in most workflows). Here is what I would normally do: Review my changes. Maybe do a git rebase --interactive to do some cosmetics on them, drop the ones that suck, reorder them to make them more logical. Now move them to the remote with git push. If this gets rejected because my local branch is not up to date: git pull --rebase to redo my work on top of the most recent changes and git push again.

Solution 4 - Git

Came across this issue after I merged a pull request on Bitbucket.

Had to do

git fetch

and that was it.

Solution 5 - Git

If your git says you are commit ahead then just First,

> git push origin

To make sure u have pushed all ur latest work in repo

Then,

> git reset --hard origin/master

To reset and match up with the repo

Solution 6 - Git

Usually if I have to check which are the commits that differ from the master I do:

git rebase -i origin/master

In this way I can see the commits and decide to drop it or pick...

Solution 7 - Git

This message from git means that you have made three commits in your local repo, and have not published them to the master repository. The command to run for that is git push {local branch name} {remote branch name}.

The command git pull (and git pull --rebase) are for the other situation when there are commit on the remote repo that you don't have in your local repo. The --rebase option means that git will move your local commit aside, synchronise with the remote repo, and then try to apply your three commit from the new state. It may fail if there is conflict, but then you'll be prompted to resolve them. You can also abort the rebase if you don't know how to resolve the conflicts by using git rebase --abort and you'll get back to the state before running git pull --rebase.

Solution 8 - Git

This happened to me once after I merged a pull request on Bitbucket.

I just had to do:

git fetch

My problem was solved. I hope this helps!!!

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionFluxEngineView Question on Stackoverflow
Solution 1 - GitiberbeuView Answer on Stackoverflow
Solution 2 - GitAbhishek GoelView Answer on Stackoverflow
Solution 3 - GitpmrView Answer on Stackoverflow
Solution 4 - GitpragmanView Answer on Stackoverflow
Solution 5 - GitPratik KhadkaView Answer on Stackoverflow
Solution 6 - GitAlexView Answer on Stackoverflow
Solution 7 - GitSylvain DefresneView Answer on Stackoverflow
Solution 8 - GitSudhir VishwakarmaView Answer on Stackoverflow