views:

1688

answers:

3

I have a local repository I'm working on and it's remote is hosted on GitHub. I recently created a branch and started working on it making several commits and now wish to push the branch to GitHub and be able to pull it to another cloned repository. What needs to be done to accomplish this?

If this is not possible using GitHub I'd be happy just knowing how to do it normally.

Any and all help is appreciated. Thanks in advanced!

+7  A: 

As you have setup the remotes already, the command is just:

git push origin branch-name

on the first push.

Afterward, using git push origin would push all branch with matching name on remote.

J-16 SDiZ
Thanks for the help, your answer was good, but Alan went just a little bit further.
PHLAK
+1  A: 

make sure that your remote URL is using SSH syntax and not just git protocol syntax. If you run,

git remote show origin

the URL printed should look something like,

[email protected]:yourname/projectname.git

You need the URL too look like that if you want to be able to push. If you are just a public user (without write access) the URL will look like,

git://github.com/yourname/projectname.git

If your looks like the latter then you can manually edit it in your projects .git/config file.

I can already push and pull to and from my GitHub repo, I'm just trying to figure out how to push and pull a branch.
PHLAK
+5  A: 
git push origin <local-branch-name>:<remote-branch-name>

Substitute for <local-branch-name> and <remote-branch-name>. They may be same or different, as you wish.

Alan Haggai Alavi
Does that mean I can then do "git pull origin <REMOTE-branch-name>:<LOCAL-branch-name>"?
PHLAK
@PHLAK: Yes, you can use the same refspec for `git pull` as well.
Alan Haggai Alavi