10

I would like to do the following in EGit:

$ git checkout -b newbranch
$ git push -u origin newbranch

This gives me a new local branch, pushes it to the upstream server and creates the right tracking reference. How do I do the same in EGit?

neelance
  • 121
  • 1
  • 1
  • 6
  • EGit 3.2 finally (February 2014) offers to set the upstream branch when pushing! See [my edited answer below](http://stackoverflow.com/a/10111655/6309) – VonC Feb 07 '14 at 12:47

2 Answers2

9

For the first operation, you can read the EGit manual "Creating a New Local Branch "

Select Team > Switch To... > New Branch

new branch dialog

For the push, see Vogella's Egit tutorial, but also the "Push ref specification"

push a branch

Note: robinst has opened bug 378960 "Allow to configure upstream in Push Branch wizard" (mentioned in "EGit - set up remote tracking correctly when creating a branch").

The problem is that this (configuring the upstream on push) is not yet done automatically when first pushing a branch.

For now you have to right click on the branch in the Git Repositories view and choose "Configure Branch", where you can set up the upstream configuration.


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
  • Sorry, but your answer is not helpful, since its result is not the one I asked for. This way, the new branch still merges from the branch it was created from (e.g. `branch.newbranch.merge = refs/heads/master`), but I would like to have a proper upstream tracking reference, like the one the `-u` flag creates. – neelance Apr 11 '12 at 22:00
  • @neelance ok I will check that tomorrow – VonC Apr 11 '12 at 22:22
  • @neelance I did check, but didn't find an obvious solution for now. – VonC Apr 19 '12 at 12:36
  • Opened a bug about being able to do `git push --set-upstream` here: https://bugs.eclipse.org/bugs/show_bug.cgi?id=378960 – robinst May 09 '12 at 11:12
  • For now you have to right click on the branch in the Git Repositories view and choose "Configure Branch", where you can set up the upstream configuration. – robinst May 09 '12 at 11:13
  • @robinst: interesting. I have included it in the answer for more visibility. – VonC May 09 '12 at 11:29
0

The UI location for creating a new branch seems strange to me.

In the Git Repository tab, select a branch you want to create a branch from it right click and then you will see Create Branch

enter image description here

Alireza Fattahi
  • 42,517
  • 14
  • 123
  • 173