I switch to master and it says I am ahead by 40 commits:
$ git checkout master
Switched to branch 'master'
Your branch is ahead of 'origin/master' by 40 commits.
But when I then do a pull it says I am up-to-date:
$ git pull origin master
From https://github.com/dmcouncil/dmWorkflow
* branch master -> FETCH_HEAD
Already up-to-date.
However I can resolve this (remove the 40 commits
msg) with:
Michaels-MacBook-Pro-2:dmWorkflow durrantm$ git push origin master
Everything up-to-date
and now the '40 commits
' message is gone:
$ git status
# On branch mdd_play_settings_and_topics_reports
nothing to commit (working directory clean)
Why do I have to do the extra push (of what seems like nothing) to get in sync?
Is there a better approach I can take to this?
This means that your local information about origin/master is different from the remote version. git fetch
will correct that. git pull
works in your case, because it also does a git fetch
.
Just adding to Jamund Ferguson's answer...
If you have multiple remotes configured you could also do a git remote update
which will fetch the information for all the remotes.
As with git fetch this will only update the information you have about the state of the remotes. It will not update or merge any code, so it is recommended to do it often to avoid strange status reports and incorrect diffs.
As a rule of thumb you would be referring to the local information of the remote branch when you use a command that uses a slash instead of a space after the remote eg. git command origin/master
and git command origin master
Usage example: git checkout origin/master
will switch to the code as per your current local information and git diff origin/master
will diff your current code with your current local information about the remote branch. This means you could easily create a branch or diff your code with an outdated information/code of the remote if you don't fetch regularly which can lead to cumbersome issues.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With