Solving the ‘Your branch is ahead of ‘origin/master’ by x commits’ issue after pulling using git.

Posted in: Bailey's Blog- Nov 30, 2011 10 Comments

This is an annoyingly simple issue – so simple that it may not be blogged elsewhere.

You have a remote repository and push some code updates to it from a local repository – you then switch to a different local repository and pull down the updated code from the remote repository with:

$ git pull origin mybranch

which updates your local mybranch nicely.

Now when you run

$ git status

it says everything is up-to-date – but you get the horrible ’Your branch is ahead of ‘origin/master’ by x commits’ message – WTF!

What this is saying is that your local branch – mybranch – is ahead of your local copy of the remote – origin/mybranch.


See – your local copy of origin/mybranch (in this case origin/6.x-1.x) still points to the previous commit.

The thing is – I was being too clever and trying to avoid pulling and updating master.  What I should have run was:

$ git pull origin

This will fetch and merge the current branch from the remote to my local branch- and also update my local tracking branch – origin/mybranch – to point to the latest commit.

If you run

$ git pull origin

after running

$ git pull origin mybranch

it seems to be safe and to sort out the issue of ’Your branch is ahead of ‘origin/master’ by x commits’.

Hopefully this quick note might help someone who found themselves in the same position as me.

10 Responses to “Solving the ‘Your branch is ahead of ‘origin/master’ by x commits’ issue after pulling using git.”

  1. Reply dan says:

    Bingo :)

    Thanks for that, was driving me insane!

  2. Reply John says:

    Awesome, was really making me nervous, what the hell am I doing wrong here?

  3. Reply Git can be confusing… « Baked Potato Technologies says:

    [...] fetch or pull – not from a specific branch. Bailey has a bit more of an explanation here. Share this:TwitterFacebookLike this:LikeBe the first to like this [...]

  4. Reply Alex says:


  5. Reply Giovane Tomaz says:

    Thanks for the explanation!

    I had this problem with a production branch and after reading this post I decided to use git fetch (I thought it would be safer) and it worked perfectly too!

  6. Reply Igor Cavalcante says:

    thanks a lot

  7. Reply Uma says:

    Thank you very much for sharing this! Saved my day

  8. Reply gazza says:

    Great, thanks!

  9. Reply deepa says:

    Thanks very much solved my problem

  10. Reply Dan says:

    Wow. Did a git pull origin and… Still says I’m 1 commit ahead of origin/master.

    Wonderful. I’m wonderfully hosed.

Leave a Reply