Alex ChaffeeAlex Chaffee
git config push.default matching
edit Posted by Alex Chaffee on Thursday June 04, 2009 at 04:29PM

Upgraded to git 1.6.3 yet? You should, and Jason Rudolph says why (and if you're on a Mac, Rob Sanheim says how.)

Sadly, after you do upgrade, when you start doing "git push", your console will start to be littered with the following oddly patronizing message:

warning: You did not specify any refspecs to push, and the current remote
warning: has not configured any push refspecs. The default action in this
warning: case is to push all matching refspecs, that is, all branches
warning: that exist both locally and remotely will be updated.  This may
warning: not necessarily be what you want to happen.
warning: 
warning: You can specify what action you want to take in this case, and
warning: avoid seeing this message again, by configuring 'push.default' to:
warning:   'nothing'  : Do not push anything
warning:   'matching' : Push all matching branches (default)
warning:   'tracking' : Push the current branch to whatever it is tracking
warning:   'current'  : Push the current branch

While I'm generally in favor of verbose warnings, this one is kind of bizarre. Essentially, it's saying, "Warning! The command you just ran will continue to operate exactly as it did before!" Guys, telling us about new options is great but that's what release notes are for.

Worse, they don't provide keystroke-level instruction beyond the offhand gerund "configuring" on how to shush it. Here's the result of my 8-minute speluking inside the output of "git help config":

git config push.default matching

[Or, thanks to Alastair Brunton below

git config --global push.default matching

]

There, now, that wasn't so hard after all, was it?

Comments

  1. Jack Dempsey Jack Dempsey on June 04, 2009 at 05:52PM

    Alex,

    I recently went through the same change, but decided to go with current instead of matching. With current I know its only the branch I'm on that's getting pushed, rather than possibly a bunch of other branches that may not be ready. Given how easy it is to switch to branches and then git push, I feel its worth the couple seconds extra effort.

    jack

  2. Alex Chaffee Alex Chaffee on June 05, 2009 at 03:35AM

    OK, fair enough. "git config push.default current" might be a good way to shush the ebullient warning.

  3. bryanl bryanl on June 05, 2009 at 09:21PM

    I just saw that error as well. I had assumed I had borked my git setup, but I did change it current just like Jack.

  4. Alastair Brunton Alastair Brunton on July 02, 2009 at 01:21AM

    Also if you have lots of repositories, you can add this to the global config with:

    "git config --global push.default matching"

    (or with one of the other push defaults)

  5. Alex Chaffee Alex Chaffee on July 02, 2009 at 07:19AM

    Thanks, Alastair!

  6. Adam Bair Adam Bair on July 06, 2009 at 10:12PM

    Thanks Alex (and Alastair) - just ran into this as well. +1 to Jack and Bryan for "current"

  7. Johann Johann on July 12, 2009 at 02:27AM

    Thanks a lot guys!

  8. Jirapong Nanta Jirapong Nanta on July 17, 2009 at 01:16AM

    Thanks.

  9. Phil Phil on July 18, 2009 at 12:37PM

    Adding my thanks: Thanks!

  10. Mitch Mitch on August 20, 2009 at 02:26PM

    So what is the difference between "tracking" and "current"?

    Where does "current" push to?

  11. Alex Chaffee Alex Chaffee on September 02, 2009 at 03:16PM

    Mitch -- Um... uh... I have no idea.

  12. Jamie Flournoy Jamie Flournoy on September 09, 2009 at 11:48AM

    So what is the difference between "tracking" and "current"?

    From 'man git-config':

    nothing: do not push anything.

    matching: push all matching branches. All branches having the same name in both ends are considered to be matching. This is the default.

    tracking: push the current branch to its upstream branch.

    current: push the current branch to a branch of the same name.

    see also: http://www.kernel.org/pub/software/scm/git/docs/git-config.html#_variables

  13. Alex Chaffee Alex Chaffee on September 09, 2009 at 12:02PM

    Thanks, Jamie.

    So when does the upstream branch not have the same name?

  14. Joseph Palermo Joseph Palermo on September 09, 2009 at 01:51PM

    When you create your local branch with a different name? (don't do that)

  15. Josh Susser Josh Susser on September 10, 2009 at 08:02AM

    @Joseph: I create local branches with names that are different from the remote name if I'm using multiple remotes. That's required if the remote branches have the same name within their respective repos. Why is that bad to do?

  16. Joseph Palermo Joseph Palermo on September 10, 2009 at 04:04PM

    It's bad because I've never done that.

    Move along... move along...

  17. dilip dilip on September 13, 2009 at 08:34AM

    thanks it helped!

  18. David T David T on September 17, 2009 at 03:45AM

    Thanks for taking the time to do this post. It was really bugging me.