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:

$ git pull --rebase

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.

$ git pull --rebase --autostash

Instead of invoking this option manually, you can also set this for your repository with git config:

$ git config pull.rebase true
$ git config rebase.autoStash true

Or you can set this globally for every Git repository:

$ git config --global rebase.autoStash true
$ git config --global pull.rebase true

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.