How to stash only unstaged changes in Git?

Question

I would like to use this workflow:

  1. Stage some changes.
  2. Save the unstaged changes to the stash.
  3. Do some stuff with the things in stage (build, test, etc.).
  4. Commit.
  5. Restore the unstaged changes.

Is there a way to do step 2?

Example:

git init
echo one >file
git add file
git commit
echo two >>file
git add file
echo three >>file
git stash push
test
git commit
git stash pop

Answer

git stash push has an option --keep-index that does exactly what you need, so run:

git stash push --keep-index

How do I git rebase the first commit?

What would I use git-worktree for?