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!
EDIT: What this is saying is that your local master branch is ahead of your local copy of the remote master branch – origin/master – which you’ve just pulled down.
EDIT: Your local master branch must have new commits which you had not pushed to origin.
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 – and – it will pull the remote master branch into origin/master and merge that into your local master branch.
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.