yf5-0w
Last Updated: September 20, 2016
·
11.61K
· khasinski
10534 128567884189 828694189 2287781 3877042 n

Like git pull --rebase? Make it default

git

As I mentioned in one of the previous protips git pull --rebase is a way to go (for most cases).

But what if you're tired of writing --rebase every single time?

Make it default.

For your repo config just set

git config branch.autosetuprebase always

and every new branch will be set to use rebase when you type git pull.

What about existing branches? Type for each of them

git config branch.YOUR_BRANCH_NAME.rebase true

If you want to use merge instead of rebase for one particular pull you can always type

git pull --no-rebase

8 Responses
Add your response

6075
736212 10200976756252420 836055407 o

Git pull is dead. You bring it back to life Dr. Frankenstein ;)

over 1 year ago ·
6110
Snoopy

For existing branches:

$ for branch in $(git for-each-ref --format='%(refname)' -- refs/heads/); do git config branch."${branch#refs/heads/}".rebase true; done
over 1 year ago ·
6116

possible to get this for every git repo locally ? a kind of global configuration of git ?

over 1 year ago ·
6168
621103 10151814410385600 1552271139 o
over 1 year ago ·
9620
Bb0525f7ad9c008dbb76c7077a2f3096

This is very dangerous! Your adjusting the default behavior of git pull. If you are on a system that isn't setup correctly, than you will merge instead of rebase.

If you create a short alias for git pull --rebase, or use the full command, you will never get into trouble!

over 1 year ago ·
9621
10534 128567884189 828694189 2287781 3877042 n

@steffex

No it isn't. You can set it up per repository, you can have your global settings changes. It's your account. If you switch a lot between different machines it's nice to have your config shared between them anyway.

Alias way is good too, but autorebase is in no way dangerous.

You can always bring back merge by doing git pull --no-rebase

Besides - it's git. If you haven't pushed it to a remote repository you can always fix it ;)

over 1 year ago ·
9622
Bb0525f7ad9c008dbb76c7077a2f3096

You change default behavior of a command, that is the dangerous part i'm talking about. Perhaps it's personal preference, but I wouldn't do it. Just to prevent screw ups!

If you need to update a repo on a remote server, you first need to check the behavior of git pull otherwise you will need to fix stuff

I agree with you that it's always fixable.

over 1 year ago ·
9623
10534 128567884189 828694189 2287781 3877042 n

I also change my config for vim, bash and many other things. It's still your account on the remote server. If it isn't you're using verbose, long commands and do not have aliases anyway. And that's when you type git pull --rebase ;)

over 1 year ago ·
Filed Under

Awesome Job

5b77d27c 0964 11e7 8e03 af0281f543eb
Operations Engineer
·
Amsterdam, Rotterdam, or remote
·
Full Time