How to save work for later

A WIP commit is a technique you can use to “put a pin in” some work you’re doing while you focus on something else. Imagine the following scenario. You:

  • Have a branch with unfinished changes that you’ve been focused on
  • Want to switch gears to get something else done
  • Don’t want to think about how your current focus work is affected by other changes in the repository
  • Don’t really want to think about commit messages for your current nebulous/in-process work

You can use a WIP commit(s) to get it done. First, create a commit with an obviously temporary commit message:

# Add everything
git checkout feature/my-deep-feature
git add -A

# Make a WIP commit (optionally add more 
# details or use some other nomenclature)
git commit -m "WIP"

Next, leave that behind in your branch and make a new branch based on your mainline (or whatever).

# Make a new branch
git checkout -b bugfix/busted-widge
git fetch origin
git reset --hard origin/main 

Now do your work for the little side project/fix … work work work … Then add and commit your work.

git add -p
git commit -m "Fix the busted widge"

# Push your new fixit branch
git push -u origin bugfix/busted-widge

# Go back to what you were working on
git checkout feature/my-deep-feature

# Optionally turn your WIP commit 
# back into pending changes (you can 
# also just keep the commit and 
# rebase/squash later)
git reset HEAD^

At this point, your feature/my-deep-feature branch is out of sync with the fixit branch. You can rebase it now…

git checkout feature/my-deep-feature
git rebase origin/bugfix/busted-widge

… or you could wait until it’s been integrated into your mainline branch.

git checkout feature/my-deep-feature
git rebase origin/main
Why not use 'git stash' for this?
It’s true you could use git stash to save work for later. However, git stash doesn’t afford you more benefit than what you get with a branch. Also you can’t push your “stash” to a remote, easily compare it with other branches, rebase it, etc. Recommendation: git stash can be useful in certain situations. But only use git stash if you need to put something aside for less than 60 seconds.