1

The goal is so after doing git clone git@somewhere:something.git

The resulting something/.git/config will contain

[push]
    default = tracking

without requiring the cloner to do cd something; git config push.default tracking so he/she won't accidentally push all branches when pushing without argument (No, nobody reads the README).

Ron
  • 7,588
  • 11
  • 38
  • 42
  • 3
    You can provide a shell script which sets the option automatically. Git provides no way to do so, because the config file might contain dangerous aliases or options. – knittl Aug 02 '12 at 17:37
  • @knittl Can the script be included in the repo, and be run automatically when the repo gets cloned? Like post-clone hook or someting? – Ron Aug 02 '12 at 17:42
  • 2
    You can include it in the repository, but you cannot have it executed automatically. Think about the security implications this would cause! – knittl Aug 02 '12 at 17:46

1 Answers1

1

Since it is difficult to enforce policy on the downstream or client side (which is dangerous, as knittl comments), the upcoming Git 2.0 recognizes that fact and will change the default push policy.

(The discussions on this date from early 2012, as illustrated in "git push current branch")

It will go from the current default one:

matching - push all branches having the same name in both ends.
This is for those who prepare all the branches into a publishable shape and then push them out with a single command.
It is not appropriate for pushing into a repository shared by multiple users, since locally stalled branches will attempt a non-fast forward push if other users updated the branch.
This is currently the default, but Git 2.0 will change the default to simple.

To the new one, called "simple":

upstream - push the current branch to its upstream branch.
With this, git push will update the same remote ref as the one which is merged by git pull, making push and pull symmetrical. See "branch.<name>.merge" for how to configure the upstream branch.

simple - like upstream, but refuses to push if the upstream branch's name is different from the local one.
This is the safest option and is well-suited for beginners. It will become the default in Git 2.0.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250