Learning center

Hand over uncommitted work without losing files

To give another engineer work you have not committed, push a commit on a scratch branch. A pasted git diff leaves out staged changes, untracked files and the contents of binary files, and the receiver sees no error for the first two.

What each form carries#

The fixture is a repository with one commit that holds a (text) and bin (binary). The working tree then has an edit to each, a staged new file s, an untracked new.txt, an untracked .gitignore, and secret.env, which that .gitignore excludes. Run with Git 2.43.

FormEdit to aEdit to binStaged sUntracked new.txtIgnored secret.env
git diff > x.patchyesnononono
git diff HEAD > x.patchyesnoyesnono
git diff HEAD --binary > x.patchyesyesyesnono
git stash pushyesyesyesnono
git stash push -uyesyesyesyesno
git stash push -ayesyesyesyesyes
git add -A && git commityesyesyesyesno

Without --binary, the patch holds the line Binary files a/bin and b/bin differ. The receiver's git apply stops with cannot apply binary patch to 'bin' without full index line and applies nothing, so a is missing too. That failure is loud. The missing new.txt is quiet: the patch applies, and the build breaks later on an import that does not exist.

Choose the form by what the receiver does next#

If the receiver continues the work, push a commit. It names its parent, so the receiver gets the base you started from as well as the change:

git switch -c handoff/export-fix
git add -A
git status --short      # read the list before you commit
git commit -m "WIP: export fix, test for empty rows still failing"
git push -u origin handoff/export-fix

Read the status output for files that should not leave your machine. git add -A respects .gitignore, so a secret in a file no rule ignores goes into the commit.

If the receiver only reads the change, git diff HEAD --binary is enough when git status --short shows no ?? line.

A stash stays in your clone unless you export it. Newer Git versions have git stash export --to-ref, which writes stashes to a ref you can push. It needs the receiver to have git stash import, so a branch is the simpler choice across a team with mixed versions.

What the receiver checks#

The receiver runs two commands and compares them with two facts in the handoff message:

git log -1 --format='%h parent %p'
git show --stat HEAD

The message should give the commit, its parent and the number of files. A count that differs means a file was added or left out after the message was written. It does not show that the work builds: an ignored local file, such as a .env or a generated client, can still be what makes it run on your machine. A fresh clone and one build command settle that, and the handoff should say whether you ran them.

Worked example#

This example is fictional. Ana hands Ben a patch for a CSV export. It applies, and the build fails on import './quote'. Ana's quote.ts was untracked, so git diff never saw it. They switch to a branch: the commit lists four files, the message says four, and Ben's fresh clone builds. The message also says that the empty-rows test fails, so Ben's first decision is about that test and not about whether he has the right files.

When the receiver cannot reach your remote, use a bundle. For the rest of the method, return to handing over evidence.

One month of free code review.

New organizations get one calendar month of hosted code review for private and public GitHub repositories. No card or cloud connection required. Eligibility and fair-use terms.

Start free with GitHub

Related reading