What changed since my last push, or on GitHub?
safe beginner #fetch#ahead#behind#compare
When to use this: You need to know what is only on your PC, and what is only on GitHub, before you pull or push.
Before you start
Steps
-
Refresh what Git knows about GitHub
terminalgit fetchUpdates the
origin/*pointers so comparisons use the latest remote state. -
Commits on my PC that GitHub does not have
terminalgit log origin/main..HEAD --onelineRead
A..Bas 'in B but not in A'. These are the commits agit pushwould upload. -
Commits on GitHub that I do not have
terminalgit log HEAD..origin/main --onelineThese are the commits a
git pullwould bring in. If this prints nothing you are up to date. -
File-level summary of the difference
terminalgit diff origin/main --statShows which files differ between your working tree and GitHub's
main, with line counts. -
Quick one-line summary
terminalgit status -sbThe top line shows
[ahead N, behind M]after a fetch.
How to verify it worked
- You know the number of commits to push (ahead) and to pull (behind).
Common errors and fixes
unknown revision origin/main Your remote or branch has another name. Run git branch -vv to see the upstream branch name, then use it. Q&A
If I am both ahead and behind, what does that mean?
The branches have diverged: you and GitHub each have commits the other lacks. You must combine them with a pull (merge or rebase) before pushing.