Pushing and Pulling Branches on Github
08/04/05
So you have multiple branches on your local machine and now you want to share one or more with the other developers on your project.
You can let everyone know your IP address and have them connect to your computer directly or if you're using GitHub, you can push your branches up to it, and then the other developers can pull your newly shared branches from there.
Heres the a few commands that you are going to need to know.
# Push your local branch to GitHub git push origin <local branch name>:refs/heads/<remote branch name>
Just by pushing your branch to a remote server doesn't mean that you are tracking it. You'll need to add the branch to your git config or you can delete the branch and then create a new one that is linked to the remote one with the following command.
# Create a new local branch that tracks a remote branch. # If you already have a branch of the same name, delete it # first and then recreate the branch from the remote repository. git branch -f <local branch name> origin/<remote branch name>
Now others can pull your branch from GitHub.
# Create a new local branch that tracks a remote branch git branch <local branch name> origin/<remote branch name>
One thing to note is that you cannot delete a remote branch from your local machnine, and as far as I've seen, GitHub doesn't have a gui to delete a branch online.
# Delete a remote branch off the remote server git push origin :<remote branch name>
You can however, remove the branch from your remote branches listing.
# Stop tracking a remote branch git branch -d -r origin/<remote branch name>
For some other great tips on using Git, check out this wiki.
Thanks to Dustin (in the comments) for pointing out this shortcut. If your want the remote branch to be named the same as your local branch you can use the following.
# Push your local branch to GitHub git push origin <local branch name>
Comments
08/04/05 - Dustin Says:
To put a new local branch on github as a remote branch:
git push origin branchname
The colon is only necessary if you want a different name there.
—track is pretty much there by default, you don’t need it.
To delete a branch from github:
git push branch :branch_name
08/04/05 - Eric Goodwin Says:
Thanks for the great info Dustin. I’ll update the post to reflect your comments.
08/04/06 - Eric Says:
Eric, thanks for the tips. Also, I really dig your blog design, but I have one little nit to pick. Your links look like regular text, until you hover over them. I was confused when I read “check out this wiki” but saw no link.
08/04/06 - Eric Goodwin Says:
@Eric, No problem. Thanks for the comment about the link text. I was thinking the same thing but hadn’t gotten around to adding any new styles yet. No time like the present I guess. I’ll add something in right now. Cheers.
08/07/01 - jpemberthy Says:
Thanks!