Git pull with automatic rebase
$ git config --global branch.autosetuprebase always
From git manual
branch.autosetuprebase
When a new branch is created with git branch or git checkout that tracks another branch, this variable tells git to set up pull to rebase instead of merge (see "branch.<name>.rebase"). When never, rebase is never automatically set to true. When local, rebase is set to true for tracked branches of other local branches. When remote, rebase is set to true for tracked branches of remote-tracking branches. When always, rebase will be set to true for all tracking branches. See "branch.autosetupmerge" for details on how to set up a branch to track another branch. This option defaults to never.
Caveat: for this to work, the option needs to be set before the branch is created. For existing branches in existing repositories you want to run
$ git config branch.YOUR_BRANCH_NAME.rebase true
Use the following oneliner to apply it to all your branches:
$ for branch in $(git for-each-ref --format='%(refname)' -- refs/heads/); do git config branch."${branch#refs/heads/}".rebase true; done
Written by Gregory Pakosz
Related protips
3 Responses
To set rebase as the default for existing branches you don't have to recreate or re-clone anything!
Just add it to the config using:
git config branch.YOUR_BRANCH_NAME.rebase true
(You may want to update your tip to include this information ;-)
Indeed thank you!
I also added a oneliner to do it for all branches