EGit pushes all local branches when no explicit RefSpec is found

Cloning a Git repository with EGit 1.0 and no further configuration causes some unexpected behavior. The moment you clone a repository, say from GitHub, everything is set up for you, and you are ready to push and pull. And since you fully adopted the Git workflow, you do create a new branch for every bug fix or new feature you are implementing. And you expect those branches to be local only. The problem with EGit is, they aren‘t. Instead, without further configuration, all branches are shared (pushed) by default.

As the Git push spec points out (refspec in options), this is correct:

The special refspec : (or +: to allow non-fast-forward updates) directs git to push “matching” branches: for every branch that exists on the local side, the remote side is updated if a branch of the same name already exists on the remote side. This is the default operation mode if no explicit refspec is found (that is neither on the command line nor in any Push line of the corresponding remotes file—see below).

But on the command line, e.g. with msysGit or on OS X, this is different. No branch is pushed by default, you have to explicitly do this. This behavior seems more useful, since most branches are not of any interest to other developers.

To avoid this strange behavior in Eclipse, every(!) developer with push rights to this Git repository has to update his local RefSpec: Select Team – Remote – Configure Push to Upstream… You can see the setting causing the problem at the bottom right away (section RefSpec): All branches will be pushed using Push Spec “refs/head/*:refs/heads/*”

Expand the Advanced section and click on the Edit button. A new dialog opens. Check the source ref combo and select the master [branch] entry. This automatically updates the destination ref. Keep this entry and click the Add spec button, Finish and then Save in the other dialog. That‘s it. From now on, only the master branch is pushed to the remote repository. In case you want to push another branch, you do have to configure it as described above too. Remember to do this for every Git repository in every workspace.

That‘s it. Unfortunately, every developer has to do this. In my eyes, this is way to complicated. The settings described here should be the default. Developers want to develop, and not to configure the same things all the time again and again. And since push and pull are enabled directly after cloning, everything seems ready.

Because of that, I have started a post in the Eclipse Community Forums. In my eyes this qualifies as a change request. As a compromise it should be possible to implement some choice in the Eclipse preferences which updates the repository parameter push.default (seems to be ignored at the moment).