84

I was just knocking around in my global .gitconfig file and I noticed that I've managed to end up with this:

[branch]
  autosetupmerge = always
  autosetuprebase = always

That seemed more than a little counterintuitive, but after doing some reading, I still have no idea whether I need both or whether it's sufficient to remove autosetupmerge and just retain autosetuprebase. Most projects that I'm working have a straight downstream->upstream flow, so rebasing is generally preferred when dealing with branches.

1
  • Update the accepted answer please Feb 13, 2019 at 2:03

5 Answers 5

133

What is counterintuitive here is the naming of these preferences. They do look like they refer to the same functionality, but in fact they don't:

  • autosetupmerge controls whether git branch and git checkout -b imply the --track option, i.e. with your setting of always,
    • git checkout branchname, if branchname exists on a remote but not locally, will create branchname tracking its remote counterpart
    • git checkout -b newbranch will create a new branch newbranch tracking whichever branch you had checked out before issuing this command
  • autosetuprebase controls whether new branches should be set up to be rebased upon git pull, i.e. your setting of always will result in branches being set up such that git pull always performs a rebase, not a merge. (Be aware that existing branches retain their configuration when you change this option.)

So it makes perfect sense to have both autosetupmerge = always and autosetuprebase = always; in fact, that's also what I have.

10
  • 4
    very nice answer. in short, avoid both and avoid pull like the plage. really. you will learn the inner workings of git and end up with a better workflow if you never use pull. either git remote update; git rebase/merge upstream/master or git fetch; git rebase upstream/master... git pull will eventually do something you are not expecting. and then you will not know enough about the inner workings. better to type a little more today and learn than to be in a cusp later that you don't know how to solve :)
    – gcb
    Dec 10, 2014 at 5:50
  • 3
    I've got the impression that these both (and even rebase) work very nicely accessing a limited number of remote repos for a handful of projects, all of which mandate the same in-house workflow. I imagine however that your advice would be very sensible for someone who plans to commit to lots of projects with all sorts of different workflows / policies.
    – laszlok
    Dec 10, 2014 at 15:35
  • 2
    to change this setting for existing branches, use: git config branch.<branchname>.rebase true
    – verboze
    Jan 26, 2017 at 16:44
  • 1
    branch.autoSetupMerge=always doesn't seem to make sense for new branches. Meaning, git checkout -b b1 would set upstream to branch master (generally) of the local repository. What's the point?
    – x-yuri
    Jul 25, 2020 at 10:37
  • 1
    @laszlok "...pushing is always to a remote..." Hmm, I haven't tried it, but according to this, a branch can have another branch of the "current local repository" set as its remote. The configuration entries would be branch.<name>.merge=<other-branch> and branch.<name>.remote=. or ...pushRemote=. (note the 'dot' specified in the latter two options). Sep 3, 2021 at 6:34
35

since this is the first hit, if you search for "autosetuprebase" with google, here an advice:

git config --global branch.autosetuprebase always

Source https://mislav.net/2010/07/git-tips/

4
  • 8
    And since rebasing can cause you to loose the will to live here's why you shouldn't Jul 25, 2014 at 14:19
  • 12
    @EliasVanOotegem I don't see any good arguments at your link. Nov 16, 2016 at 9:53
  • 3
    I wrote this answer five years ago. I don't use it any more. I prefer to merge today. But I am not married with my current git workflow. Maybe I will do it different in the future. The topic "merge vs rebase" has low priority for me today. I love "show history for selection" of my favorite IDE. I care for this much more. If you look at the changes with "show history for selection" it does not matter at all, if rebase of merge was used. The result is important, not the road to it.
    – guettli
    Feb 7, 2017 at 10:54
  • 1
    My personal opinion: Some things in live are really important: finding a partner, raising a family, having a cool job, having friends, being curious, stay healthy. I don't participate in the "rebase vs merge" discussion any more. I use what my teams suggests. This leaves more mental energy for important decisions.
    – guettli
    Apr 23, 2020 at 9:42
28

It's probably worth mentioning that there is a difference between autosetupmerge=always (in your config) and autosetupmerge=true (the default).

true will only setup merging for remote branches. always will include local branches as well.

You probably want true.

1
  • As of git 2.37+, I would argue you probably want simple, instead :)
    – Tao
    Jan 13 at 15:59
28

As I was looking for other possible options of "autosetuprebase" and it took some time to find them, here they are:

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..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.

Source: http://git-scm.com/docs/git-config.html

-15

You probably don't need to set up autosetupmerge---the default is true.

3
  • 3
    As RyanK said below, "always" and "true" result in different behaviour.
    – laszlok
    Mar 3, 2014 at 12:47
  • See answer from @laszlok below for an excellent explanation of both autosetupmerge and autosetuprebase. See branch.autosetupmerge and branch.autosetupconfig in the git help for more info: kernel.org/pub/software/scm/git/docs/git-config.html.
    – Olly
    Jun 11, 2014 at 14:28
  • 1
    For me, the main utility of autosetupmerge=always is that it establishes the upstream relationship of new branches created with git checkout -b. I have no idea why this behaviour is not the default, but it definitely avoids confusion to have this set to 'always'.
    – mgiuca
    Jun 30, 2014 at 0:52

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.