3

When I create a new branch from a remote branch using EGit I get the wrong remote tracking set up:

I create the local branch feature1 from the remote branch refs/heads/master and immediately push to upstream. The followign remote tracking gets configured in my .git/config file:

[branch "feature1"]
    remote = origin
    merge = refs/heads/master

So, pull and push in that branch will pull and pull from/to the remote master branch. I would expect the following tracking configuration instead:

[branch "feature1"]
    remote = origin
    merge = refs/heads/feature1

I know I can fix it even from EGit, but I'm worried about other developers in my team not realizing this and pushing uncompleted features to the master branch.

Am I doing something wrong?

mmutilva
  • 18,688
  • 22
  • 59
  • 82
  • Egit 3.2 finally (February 2014) offers to set the upstream branch when pushing! See [my edited answer below](http://stackoverflow.com/a/10547268/6309) – VonC Feb 07 '14 at 12:49

2 Answers2

1

Egit will, by default, take the upstream branch for the merge parameter when creating a branch from a remote one.
That means, if you want to enforce the policy which is to push to remote/master only from a local branch master, you can try and enforce it locally.

Check if Egit respects a git config push.default current for pushing only the current branch to an upstream branch with the same name (which might actually become the default policy after git1.7.10).
However, that has the issue of making sure every developer has that policy active in his/her repo.

(I don't think you can enforce it at the "central" repo one, where you could add a server-side hook like an update hook: that script take the name of the branch being updated (ie here 'master', not the name of the branch in the downstream repo, ie here 'feature1')


Note: bug 378960 has been marked as resolved (February 2014) in Egit 3.2:

Push Branch / Initial Push wizard simplifies pushing a branch and also allows upstream configuration for new branches created by the push operation:

https://wiki.eclipse.org/images/6/6f/Egit-3.2-PushBranchWizard.png

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

Maybe you should advise developers to create feature-branches not from the remote-tracking branch (e.g. origin/master), but from the local one (master). This way, EGit will not set up any remote tracking by default.

If you then decide to publish the branch for the first time, it should be possible to set up the remote tracking (the equivalent of git push --set-upstream) after bug 378960 is implemented.

robinst
  • 30,027
  • 10
  • 102
  • 108
  • Not a very good answer if you need to push a shared project branch up to github. In this case, there's no reason you shouldn't be able to just set up the remote tracking properly on creation. – Johnathon Sanders Jun 06 '12 at 15:58
  • I have edited my answer below to reflect that bug 378960 is finally resolved! – VonC Feb 07 '14 at 12:49