5

This feels like im missing something obvious, but i've been reading tutorials for 3 days and can't seem to make it happen.

I have a private repo on github. I want to run it as two separate branches. As I understand it, I clone the repo so its on my local machine, then branch it using

git branch newbranch

git checkout newbranch

so far so good. Now i make some changes, commit to newbranch. It seems like I can push this all to my remote repo intact, but I'm having trouble doing it without simply merging it with master, which is not what I want to do. How can I put my branches on github intact?

Is this the correct workflow for doing this? If it is, what am I doing wrong?

Vagabond_King
  • 123
  • 1
  • 1
  • 10

2 Answers2

5

this will only push the newbranch to origin/newbranch on github:

git push origin newbranch:newbranch
Tomas Markauskas
  • 11,496
  • 2
  • 33
  • 35
5

Just:

 git push origin mybranch

should be enough; it will push the HEAD of the current branch you are in (not master, but the one you are working on) to a similary named branch. if the remote branch has not the same name, then

git push origin mybranch:remotebranch

git push uses a refspec to specify with what <src> object the <dst> ref in the remote repository is to be updated.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • I think`git push origin mybranch` would push mybranch, no matter what's the current branch, to origin. not HEAD of current branch. – jsvnm Aug 30 '12 at 13:59
  • @jsvnm but the premise of the question was that `'mybranch'` was checked out. `HEAD` references mybranch (called '`newbranch`' in the OP's question). Note that the push policy might change with Git2.0: http://stackoverflow.com/questions/11782825/git-config-that-gets-cloned/11783210#11783210 – VonC Aug 30 '12 at 18:09