Git tip: autostash with git pull --rebase
A less well known, but a very useful Git feature that I have been using for a while is autostash. When you’re working on a project and have some local commits, you often want to pull in the changes your co-workers pushed to the remote repository and rebase your commits on top of that with:
If there are uncommitted changes, you need to stash those changes first, then pull the remote updates, and pop your stash to continue your work. This gets quite tedious, but since Git 2.6 you can use the autostash option to automatically stash and pop your uncommitted changes.
Instead of invoking this option manually, you can also set this for your repository with git config
:
Or you can set this globally for every Git repository:
The --autostash
option only works with --rebase
, so it makes sense to set these two together. You can read more about in the Git documentation.