Using git commits instead of git stashPosted 14.11.2019
Over the years I have time and time again run into the problem of getting conflicts when popping from the git stash. Somehow this has resulted in loss of parts of the work I have done. There is probably a correct way to use stash in these situations. However, commits is a much bigger part of my workflow and I have deeper knowledge of how to work with commits. Furthermore, if I learn more about tricks around commits it will be helpful in the rest of my workflow.
I started to use wip commits a lot instead. I just add everything and commit it
with the commit message
wip. Git has this nice feature to make new commands
that are either aliases to other git commands or shell commands. To aid working
with wip commits I created these two aliases:
wip = "!git add . && git commit -nm'wip'"pop = reset HEAD^
The first alias, wip, does two git operation through a shell command. The exclamation
mark in the beginning of the alias indicates that this is a shell command. The
first operation is adding everything in the current folder, and then the
second operation is committing the changes. The flag
-n in this command
tells git to skip any pre-commit hooks since I don't want a linter or anything
stopping the creation of the wip commit.
The second alias, pop, will remove the last commit and unstage the changes. This means
that if I do some changes in a repo and run
git wip and then
git pop the state
would be the same after
git pop as it was before
Adding this to my workflow has made it much easier to put away work temporary by running git wip in a branch. Or rebasing my current work on the latest master, which has the possibility of creating tedious conflict situations.