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

  1. Refresh what Git knows about GitHub

    terminal
    git fetch

    Updates the origin/* pointers so comparisons use the latest remote state.

  2. Commits on my PC that GitHub does not have

    terminal
    git log origin/main..HEAD --oneline

    Read A..B as 'in B but not in A'. These are the commits a git push would upload.

  3. Commits on GitHub that I do not have

    terminal
    git log HEAD..origin/main --oneline

    These are the commits a git pull would bring in. If this prints nothing you are up to date.

  4. File-level summary of the difference

    terminal
    git diff origin/main --stat

    Shows which files differ between your working tree and GitHub's main, with line counts.

  5. Quick one-line summary

    terminal
    git status -sb

    The 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.

Practice these as flashcards →

Terms in this scenario

Related scenarios

My notes

Saved in this browser only.