Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git warning: push.default is unset; its implicit value is changing

Tags:

git

push

When I push to remote in Git, I get this warning:

warning: push.default is unset; its implicit value is changing in
Git 2.0 from 'matching' to 'simple'. To squelch this message
and maintain the current behavior after the default changes, use:

  git config --global push.default matching

To squelch this message and adopt the new behavior now, use:

  git config --global push.default simple

See 'git help config' and search for 'push.default' for further information.
(the 'simple' mode was introduced in Git 1.7.11. Use the similar mode
'current' instead of 'simple' if you sometimes use older versions of Git)

To **********************************
   6b9a6d2..3ab1eab  master -> master

What does this warning mean and what should be done about it?

like image 233
JackSun Avatar asked Nov 01 '13 04:11

JackSun


3 Answers

This warning was introduced in Git 1.7.11 along with the simple style of pushing. The issue is that the current default, matching, can result in inexperienced users force pushing when some branches are behind their remote equivalent because the branches simply aren't up-to-date. The end result is that they end up rewinding the branch and potentially losing their work or someone else's. The simple mode was introduced as a new push.default behavior and will become the default in Git 2.0 (which should hopefully be out sometime early next year).

The new simple behavior is a lot like the upstream setting: it only pushes the current branch that you're currently on, if it has a remote branch that it's tracking. It adds one extra criteria: the remote branch must have the same name as the local one.

As you discovered, the way to get rid of the message is to set push.default. To get the new behavior, use:

git config --global push.default simple

To get Git's default behavior but without the warning message, use:

git config --global push.default matching

I'd really advise against using matching though. In general, most people really want the new simple behavior, or upstream.

like image 144
John Szakmeister Avatar answered Nov 02 '22 03:11

John Szakmeister


Update February 2016:

git 2.8 (March 2016) removed that big warning message.

See commit 2f27520 (25 Feb 2016) by Matthieu Moy (moy).
(Merged by Junio C Hamano -- gitster -- in commit 15be621, 26 Feb 2016)

push: remove "push.default is unset" warning message

The warning was important before the 2.0 transition, and remained important for a while after, so that new users get push.default explicitly in their configuration and do not experience inconsistent behavior if they ever used an older version of Git.

The warning has been there since version 1.8.0 (Oct 2012), hence we can expect the vast majority of current Git users to have been exposed to it, and most of them have already set push.default explicitly. The switch from 'matching' to 'simple' was planned for 2.0 (May 2014), but actually happened only for 2.3 (Feb 2015).

Today, the warning is mostly seen by beginners, who have not set their push.default configuration (yet). For many of them, the warning is confusing because it talks about concepts that they have not learned and asks them a choice that they are not able to make yet. See for example "Warning: push.default is unset; its implicit value is changing in Git 2.0" (1260 votes for the question, 1824 for the answer as of writing)

Remove the warning completely to avoid disturbing beginners. People who still occasionally use an older version of Git will be exposed to the warning through this old version.

Eventually, versions of Git without the warning will be deployed enough and tutorials will not need to advise setting push.default anymore.


Original answer (March 2014)

That warning will soon change in git 2.0 (Q2 2014), with commit 289ca27 and commit 11037ee:

push.default is unset; its implicit value has changed in Git 2.0 from 'matching' to 'simple'.
To squelch this message and maintain the traditional behavior, use:

git config --global push.default matching

To squelch this message and adopt the new behavior now, use:

git config --global push.default simple

When push.default is set to 'matching', git will push local branches to the remote branches that already exist with the same name.

Since Git 2.0, Git defaults to the more conservative 'simple' "behavior, which only pushes the current branch to the corresponding remote branch that 'git pull' uses to update the current branch.

See more at "Why is pushing to matching the default in Git?".

like image 45
VonC Avatar answered Nov 02 '22 03:11

VonC


I solve it by providing it with remote repository name and remote branch name (which has been tracked).

In my case, in github

$ git push origin main

like image 1
CoffeePlease Avatar answered Nov 02 '22 05:11

CoffeePlease