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

Next Post

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.

Next Post Share Post :


  • dan
    22nd December 2011 at 9:16 pm http://a%20rel='nofollow'%20class='comment-reply-link'%20href='#comment-2'%20onclick='return%20addComment.moveForm(%20comment-2,%202,%20respond,%202277%20)'%20aria-label='Reply%20to%20dan'%20-%20Reply/a

    Bingo 🙂

    Thanks for that, was driving me insane!

  • John
    10th March 2012 at 9:55 pm http://a%20rel='nofollow'%20class='comment-reply-link'%20href='#comment-3'%20onclick='return%20addComment.moveForm(%20comment-3,%203,%20respond,%202277%20)'%20aria-label='Reply%20to%20John'%20-%20Reply/a

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

  • Alex
    8th May 2014 at 1:35 pm http://a%20rel='nofollow'%20class='comment-reply-link'%20href='#comment-5'%20onclick='return%20addComment.moveForm(%20comment-5,%205,%20respond,%202277%20)'%20aria-label='Reply%20to%20Alex'%20-%20Reply/a


  • Giovane Tomaz
    15th May 2014 at 8:33 pm http://a%20rel='nofollow'%20class='comment-reply-link'%20href='#comment-6'%20onclick='return%20addComment.moveForm(%20comment-6,%206,%20respond,%202277%20)'%20aria-label='Reply%20to%20Giovane%20Tomaz'%20-%20Reply/a

    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!

  • Igor Cavalcante
    29th May 2014 at 3:18 pm http://a%20rel='nofollow'%20class='comment-reply-link'%20href='#comment-7'%20onclick='return%20addComment.moveForm(%20comment-7,%207,%20respond,%202277%20)'%20aria-label='Reply%20to%20Igor%20Cavalcante'%20-%20Reply/a

    thanks a lot

  • Uma
    27th October 2014 at 10:03 am http://a%20rel='nofollow'%20class='comment-reply-link'%20href='#comment-8'%20onclick='return%20addComment.moveForm(%20comment-8,%208,%20respond,%202277%20)'%20aria-label='Reply%20to%20Uma'%20-%20Reply/a

    Thank you very much for sharing this! Saved my day

  • gazza
    23rd January 2015 at 11:28 pm http://a%20rel='nofollow'%20class='comment-reply-link'%20href='#comment-9'%20onclick='return%20addComment.moveForm(%20comment-9,%209,%20respond,%202277%20)'%20aria-label='Reply%20to%20gazza'%20-%20Reply/a

    Great, thanks!

  • deepa
    19th February 2015 at 12:03 pm http://a%20rel='nofollow'%20class='comment-reply-link'%20href='#comment-10'%20onclick='return%20addComment.moveForm(%20comment-10,%2010,%20respond,%202277%20)'%20aria-label='Reply%20to%20deepa'%20-%20Reply/a

    Thanks very much solved my problem

  • Dan
    10th November 2015 at 5:44 pm http://a%20rel='nofollow'%20class='comment-reply-link'%20href='#comment-11'%20onclick='return%20addComment.moveForm(%20comment-11,%2011,%20respond,%202277%20)'%20aria-label='Reply%20to%20Dan'%20-%20Reply/a

    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