List local Git commits that have not reached the remote

Compare your branch with its upstream, inspect commits absent from fetched remote refs, and distinguish commit identity from patch equivalence.

Best practices
Illustration of Git branches and version history

Use git log '@{u}..HEAD' --oneline to list commits on your current branch that are not reachable from its configured upstream. Fetch first so the comparison uses recent remote information.

git fetch origin
git log '@{u}..HEAD' --oneline
# Or choose the comparison branch explicitly:
git log origin/main..HEAD --oneline

Replace origin and main with the remote and branch you intend to compare. These commands inspect local refs; they do not ask every server whether a commit has ever been pushed. Your upstream can also differ from your push destination.

Check all local branches

git fetch --all
git log --branches --not --remotes --oneline

This lists commits reachable from local branch refs but absent from all currently stored remote-tracking refs. It excludes commits found on any such remote ref, even if they have not reached the particular remote where you want them. Narrow fetch refspecs, skipped remotes, shallow history, and stale refs can affect the result. Tags and detached-HEAD-only work are not included by --branches.

Count and review the changes

git rev-list --count '@{u}..HEAD'
git status
git log '@{u}..HEAD' --stat
git diff '@{u}...HEAD'

The count and status ahead/behind information use commit reachability. The three-dot diff shows the difference from the merge base to HEAD; when branches have diverged, it is not the same as comparing the two endpoint trees. Use git diff '@{u}' HEAD for that endpoint comparison.

Compare equivalent patches

git cherry -v

With an upstream configured, git cherry marks a commit - when it finds an equivalent patch upstream and + when it does not. A cherry-picked commit can have a different ID yet an equivalent patch. These signs do not mean “was pushed” or “was never pushed,” and patch equivalence is not a general proof that complete branch states are interchangeable.

FAQ

What if there is no upstream?

Compare against an explicit remote-tracking branch. To configure tracking without publishing anything, use git branch --set-upstream-to=origin/feature-x when that ref exists. git push -u origin feature-x also configures it, but actually publishes the branch.

How do I compare with a specific remote?

Name a target such as upstream/main..HEAD. For a multi-remote workflow, decide which destination matters before describing a commit as unpushed.

Why do log and cherry disagree?

Log compares the commit graph. Cherry compares patches. Both can be correct while answering different questions.

See git-log, git-cherry, git-rev-list, and git-diff.

Get a tailored plan

Contact us

Join the community

Scan with WeChat
to join the community

Try Guance

Start online and pay only for what you use.

Get started

Choose a Guance plan

Code hosting