git: your branch is ahead of 'origin/master' by 1 commit after pull
Git reports that:
Your branch is ahead of 'origin/master' by 1 commit (or X commits)
after you do the git pull origin master.
The sequence of actions:
- There is a change in the
origin/master - We do the
git pull origin master - The change is received and merged
git statusshows "Your branch is ahead of 'origin/master' by 1 commit."
The reason is that after the pull origin master the reference to the
remote origin/master is not changed (still points to the older version)
and only your local copy of the branch is updated.
The problem is that git pull origin master is the wrong command (unless you intentionally
wanted to only update the local branch).
Solution: use git pull instead.
It will fetch remote changes, update remote references and merge remote changes to your local branch.
Or use git fetch. It will fetch remote references, but will not merge to your
local branch, and you do it manually by running git merge origin/master.
To check the state, run:
git diff origin/master
It will show the difference and it should be the last master change.
To fix the problem, run:
git fetch origin
This will update git links to remotes.
If you have this problem then you likely wanted to just do git pull instead of git pull origin master.
Links
Stackoverflow: 'git pull origin mybranch' leaves local mybranch N commits ahead of origin. Why?
Git repo on a machine with zero commits is ahead of remote by 103 commits.. !
Stackoverflow: Differences between git pull origin master & git pull origin/master
Stackoverflow: Why do I have to push the changes I just pulled from origin in Git?