You committed a fix on Tuesday, switched to something urgent, and never pushed. Now a teammate asks where that fix is. It exists, but only on your laptop, in a repository you haven’t opened since.
Git can tell you what is unpushed. It answers one repository at a time, so start there, then ask all of them at once.
Finished branches pile up too: see how to delete merged and stale branches.
Still working on the change? See when to stash edits, make a WIP commit, or open a worktree before you switch tasks.
How to check unpushed commits in Git?
After fetching, run git log --oneline @{u}..HEAD to list commits on your current branch that its upstream doesn’t have.
From inside the repository, refresh your local copies of remote branches with pruning disabled, then compare your branch with its upstream:
git fetch --all --no-prune --no-prune-tags &&
git log --oneline @{u}..HEAD
@{u} is the upstream of your current branch. In this example, the branch has two commits that its upstream doesn’t have.
18fc5d5 Add coupon field
ccd1e6e Fix cart rounding
No output means your branch has no commits ahead of its upstream. If Git answers no upstream configured for branch, your branch has no tracking branch set. A push can succeed without setting one.
For a one-line answer on the branch you are on (see what “ahead of origin” means):
git status -sb
## main...origin/main [ahead 2]
If those commits landed on the wrong branch, see how to move them to a new branch.
If your push is rejected with “fetch first” or “non-fast-forward”, fetch the branch and bring in its commits before pushing again.
Every branch, not only the one you are on
Unpushed work often sits on a branch you left days ago. List them all with their state:
git for-each-ref \
--format='%(refname:short) %(upstream:short) %(upstream:track)' refs/heads
feature/exports origin/feature/exports [gone]
feature/search origin/feature/search [ahead 1]
hotfix/tax
main origin/main [ahead 2]
scratch
[ahead 2] means two commits ahead of the branch’s upstream. [gone] means the named upstream ref is missing locally. A blank upstream can mean tracking is unset, as on hotfix/tax and scratch here. It can also mean the fetch refspec leaves out a configured upstream, as in a single-branch clone. The next command lists commits from all local branches that are outside the local remote-tracking refs.
git log --oneline --branches --not --remotes
3c8d671 Export orders
b31c506 Search by SKU
2e8648c Fix tax rate
18fc5d5 Add coupon field
ccd1e6e Fix cart rounding
This checks the remote-tracking refs Git has locally. An unfetched branch may already contain a commit this command lists, and a stale ref may still point to a commit a remote branch no longer contains.
Every repository in a folder
If your repositories sit side by side in one folder (~/code/web, ~/code/api), one loop asks each of them:
for d in ~/code/*/; do
[ -d "$d.git" ] || continue
git -C "$d" fetch --all --no-prune --no-prune-tags --quiet || continue
repo=$(basename "$d")
LC_ALL=C git -C "$d" for-each-ref refs/heads \
--format='%(refname) %(upstream) %(upstream:track)' |
while read -r branch upstream tracking; do
name=${branch#refs/heads/}
if [ -z "$upstream" ]; then
if git -C "$d" config --get "branch.$name.merge" >/dev/null; then
tracking='[upstream unavailable]'
else
tracking='[no upstream]'
fi
fi
case "$tracking" in
'[no upstream]'|'[upstream unavailable]'|'[gone]')
count=$(git -C "$d" rev-list --count "$branch" --not --remotes) || continue
printf '%s/%s %s [%s outside fetched refs]\n' "$repo" "$name" "$tracking" "$count"
;;
*'[ahead '*) printf '%s/%s %s\n' "$repo" "$name" "$tracking" ;;
esac
done
done
api/main [ahead 1]
api/scratch [upstream unavailable] [2 outside fetched refs]
web/feature/exports [gone] [1 outside fetched refs]
web/feature/search [ahead 1]
web/hotfix/tax [no upstream] [1 outside fetched refs]
web/main [ahead 2]
web/scratch [no upstream] [0 outside fetched refs]
[ -d "$d.git" ]skips folders that are not a repository’s main folder. A linked worktree has a.gitfile instead, and it shares its repository’s branches, so without this line a worktree in~/codelists every branch a second time.- The fetch refreshes remote-tracking refs.
--no-prunekeeps stale refs for branches deleted on the remote.--no-prune-tagsoverrides tag-pruning settings that can make a fetch fail when a local and remote tag share a name but point to different objects. If a fetch fails, the loop skips that repository. [no upstream]means tracking is unset.[upstream unavailable]means tracking is set but Git can’t name a local upstream ref.[gone]means Git can name the ref but it is missing locally.[N outside fetched refs]counts commits outside all local remote-tracking refs, including any stale ones. The count can include commits you already pushed, as onapi/scratch, and a zero still appears, as onweb/scratch.[ahead N]compares a branch with its own upstream.
Save it as a script and you have a check you can run any time.
Where the loop stops working
- Repositories outside the folder. It looks one level deep in one folder. A repository cloned somewhere else, or nested a level down, is never asked.
- Changes you haven’t committed. It lists commits only. Edits still sitting in a working folder need their own check: see how to find uncommitted changes.
- It only reports. You still open each repository to read the commits (see how to preview what you are about to push) and push them. Found one you don’t want to send? See how to undo the last commit before you push it.
- It only reports. You still open each repository to read the commits (see how to preview what you are about to push) and push them. Before you do, you can tidy the unpushed ones.
- You have to remember to run it. The commits you forgot are the ones you forget to check for.
Found a branch that’s ready to share? Push it without checking it out and keep working on your current branch.
Or let your Mac keep watch
push& (Pushand) is a Mac menu bar app that does this for you. Point it at a parent folder and it finds the repositories inside, worktrees included, and keeps a count of the commits waiting to be pushed. Expand a repository to read its waiting commits in the menu, or click a ready branch to push. Free for 3 repositories, and every install starts with a 14-day trial, no card and no account.