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

Push a Git branch without checking it out

Push a finished branch by name while you keep editing another. Check the remote destination and confirm your checkout stayed put.

Your cart fix is ready to share, but you’re halfway through an edit on another branch. Give git push the local branch followed by the remote branch as source:destination. Your current branch and uncommitted edits stay where they are.

Name the branch and check the remote

In this example, you’re working on feature/search in acme/web. You want to publish the committed fix from fix/cart-rounding as review/cart-rounding on origin.

src=refs/heads/fix/cart-rounding
dst=refs/heads/review/cart-rounding
git status --short --branch
git diff HEAD -- notes.md
git log -1 --format=%s "$src"
git remote get-url origin
git remote get-url --push --all origin

The log should show the tip of the branch you meant to send, Fix cart rounding here. The refs/heads/ prefix makes both names branch names, even if a tag has the same name. If you’re unsure which branch has the fix, find your unpushed commits first.

The two URL commands should each print the same single URL for the repository you intend to publish to. In this example, both print ../remote/acme/web.git. If they differ or there are multiple push URLs, choose a named remote that reads from and pushes to the same single repository. Check its URLs and use its name in place of origin throughout.

Preview the push, then send it

git push --dry-run --no-verify --no-follow-tags \
  --recurse-submodules=check origin \
  refs/heads/fix/cart-rounding:refs/heads/review/cart-rounding
To ../remote/acme/web.git
 * [new branch]      fix/cart-rounding -> review/cart-rounding

Read the arrow from local branch to remote branch. Here Git would create review/cart-rounding. --no-verify skips your local pre-push hook during the dry run. The server still decides whether to accept the real push.

Fetch the comparison branch from the same remote. If the destination branch already exists, use base="$dst". For a new branch, use the branch you expect to merge into, main here.

base=refs/heads/main
git fetch --no-tags --no-prune --no-prune-tags \
  --no-recurse-submodules origin "$base" &&
  git log --oneline FETCH_HEAD.."$src" &&
  git diff --stat FETCH_HEAD..."$src"

The log shows commits on the local branch that are missing from the comparison branch. The diff lists the files your branch changed since the branches split. For the changes line by line, see how to preview the full diff.

When the destination and changes look right, remove both --dry-run and --no-verify so Git runs your local hook. Keep --no-follow-tags to skip extra tags. The --recurse-submodules=check flag checks locally known remote refs and can skip a submodule with no configured remote. If your branch records a new submodule commit, verify that commit is available from the submodule’s remote before pushing.

git push --no-follow-tags \
  --recurse-submodules=check origin \
  refs/heads/fix/cart-rounding:refs/heads/review/cart-rounding

If Git rejects the push because the destination has commits you don’t have, review that branch’s history before retrying.

Verify the remote and your checkout

Query the same named remote. Match the exact destination ref and compare its commit ID with the local branch tip.

local_oid=$(git show-ref --verify --hash "$src") &&
  remote_refs=$(git ls-remote --exit-code origin "$dst") &&
  expected=$(printf '%s\t%s' "$local_oid" "$dst") &&
  printf '%s\n' "$remote_refs" | grep -Fx "$expected" >/dev/null &&
  printf 'Verified %s at %s\n' "$dst" "$local_oid" &&
  git status --short --branch &&
  git diff HEAD -- notes.md

The Verified line confirms that the exact remote branch points to the local commit. Status should still show feature/search, and the diff should match the edit to notes.md you saw before the push. If the Verified line is missing, inspect the remote branch before pushing again.

Push a ready branch from the menu bar

In push& (Pushand), expand the repository to see which branches have commits waiting. You can push a ready branch without a working folder and keep your current checkout open.

More Git how-tos