Green Moon Software, LLC

A Different "git stash" Workflow

Git has a great little tool called “stash”. Stashing a change allows you to temporarily save your work. This is great when you are working  on a branch, but need to address some other issue or feature on a different branch. Git stashes are able to be popped onto any other branch. That seems quite powerful, but in reality, I have found it to be too flexible.

I have noticed that I rarely pop a stash from one branch to another. Instead, my “stashes” are usually context specific for the original branch. Therefore, I prefer a sort of “hard stash”. A workflow that I have used is creating a temporary commit, then resetting the commit when I come back.

For example:

$ git add .
$ git commit -m “WIP: Working on feature X”

Then I am able to switch to a different branch to address the issue or bug. After fixing committing and pushing the fix for the issue, I switch back to the original branch.

$ git checkout original-branch
$ git reset HEAD^

This removes the commit and marks the changes as pending. This workflow allows you to keep branch specific stashes. It keeps your real stash clean for times you truely need them.

comments powered by Disqus