Black Friday sale: 30% off Pro and Unlimited, until 22 December

How to see what you are about to push in Git

Read the commits, the files and the diff that a push would send, branch by branch, with plain Git before you run it.

You have been on main all afternoon and the push is one keystroke away. Before you send it, you want to know what is in it: which commits, which files, and whether anything slipped in that you did not mean to share.

Git answers all three. Compare your branch with its upstream and read the result in three levels: commits, files, then lines.

The commits

From inside the repository, refresh your copy of the remote first, with pruning off:

git fetch --no-prune --no-prune-tags

Then list what your branch has that its upstream doesn’t.

git log --oneline @{u}..HEAD

@{u} is the upstream of the branch you are on. Here, two commits are waiting.

0d936e6 Add coupon field
824e01c Fix cart rounding

Newest comes first. If the list is empty, a push has nothing to send.

The files

To see which files those commits touch, ask for a summary of the whole range.

git diff --stat @{u}...HEAD
 notes.md      | 1 +
 src/cart.js   | 2 +-
 src/coupon.js | 1 +
 3 files changed, 3 insertions(+), 1 deletion(-)

The three dots matter. They compare your branch with the point where it split from its upstream, so you see only your own changes, even when someone else has pushed to the upstream since. With two dots, those commits would show up as changes you are about to undo.

Want the kind of change per file rather than a count of lines?

git diff --name-status @{u}...HEAD
M	notes.md
M	src/cart.js
A	src/coupon.js

M is modified, A is added. To see the files commit by commit, which tells you which commit to blame for a surprise in the list:

git log --stat --format='%h %s' @{u}..HEAD
0d936e6 Add coupon field

 src/coupon.js | 1 +
 1 file changed, 1 insertion(+)
824e01c Fix cart rounding

 notes.md    | 1 +
 src/cart.js | 2 +-
 2 files changed, 2 insertions(+), 1 deletion(-)

The lines

When a file looks odd, read the change itself, limited to that path.

git diff @{u}...HEAD -- src/cart.js
@@ -2,4 +2,4 @@ export function total(items) {
   const sum = items.reduce((n, i) => n + i.price, 0);
   const tax = sum * 0.17;
-  return sum + tax;
+  return Math.round((sum + tax) * 100) / 100;
 }

Leave the path off and you get the whole diff. This is the moment to spot a debug line, a stray file or a secret you did not mean to commit.

A branch with no upstream

A new branch has no upstream yet, so @{u} has nothing to point at.

fatal: no upstream configured for branch 'fix/login'

Name the base yourself instead. Use the branch it will be merged into, for example origin/main:

git log --oneline origin/main..HEAD

Everything above works the same with origin/main in place of @{u}. It lists every commit your branch has that origin/main lacks.

Rehearse the push

Preview which refs Git would update on the remote. --no-verify skips your local pre-push hook during the dry run.

git push --dry-run --no-verify
To git.example.com:acme/web.git
   e7e5915..0d936e6  main -> main

It shows the branch and the range of commits that would move. For a new branch, add the destination you intend:

git push --dry-run --no-verify -u origin fix/login
To git.example.com:acme/web.git
 * [new branch]      fix/login -> fix/login
Would set upstream of 'fix/login' to 'fix/login' of 'origin'

When you’re ready to push, remove both --dry-run and --no-verify so Git runs your local hook. The server applies its branch rules to the real push. To catch a slip before it reaches the server, see how to stop accidental pushes to production.

Sending a release tag on its own? See how to preview and push a single tag.

Not happy with what you see?

While those commits are still unpushed, you can fold, fix and reorder them. See how to tidy unpushed commits.

The same view for every repository

These commands look at one branch of one repository. To ask the question across every branch and every repository you have, see how to find unpushed commits.

Ready to send a branch while you’re editing another? See how to push it without checking it out.

Spotted a commit you don’t want to send? Read how to undo it before you push.

Found one fix that’s ready among unfinished commits? See how to push just that commit.

Rewrote history and need to force push? Read how to do it with a lease.

Or see it before you click

push& (Pushand) is a Mac menu bar app that lists the commits waiting on each branch and can show the files they change, all together or one commit at a time, before you push. Click a branch to send it. Free for 3 repositories, and every install starts with a 14-day trial, no card and no account.

See how it works

More Git how-tos