I had an existing local branch that I had done some commits to and wanted to create a remote branch on origin so that I could check it out to other local branches on different machines. The current version of Git (1.6.1.x at the time of this writing), doesn’t seem to have an elegant way of doing this, but still I was able to do it fairly simply by manually editing Git’s “config” file (inside of the “.git” folder of a working directory).I first created a remote branch (this assumes that I already had a local branch named “new_feature_name”):
git push origin origin:refs/heads/new_feature_name
Then, I edited the config file and added an entry to connect the local branch to the remote branch:
[branch "new_feature_name"]
remote = origin
merge = refs/heads/new_feature_name
You can also do this with git config by:
git config branch.new_feature_name.remote origin
git config branch.new_feature_name.merge refs/heads/new_feature_name
I then checked out the local branch and tried to push it to the remote one with:
git push origin new_feature_name
but got some kind of error about divergent branches, so I pulled the remote branch to the local one with:
git pull origin new_feature_name
and this seemed to merge the two together well enough so that I could then do a:
git push
On another machine, I then did a:
git pull
and created a new local branch that tracked the remote one with:
git checkout --track -b new_feature_name origin/new_feature_name
Thanks to this post for examples of setting up remote branches.
- git: Error: Some Local Refs Could Not Be Updated; Try Running ‘git remote prune origin’ To Remove Any Old, Conflicting Branches Lately I have been working on a Ruby project that...
- How To Switch Between Git Branches From The Linux CLI If you are using Git for version control then it...
- Delete a Remote Branch from GitHub Deleting a remote branch from a GitHub account is easy...
- msysgit clone Error – fatal: Cannot update the ref ‘HEAD’ I wanted to start syncing a git project to my...
- TortoiseSVN: Update Local Repository for a Remote Repository That Has Moved If you have been working on a project that is...
Tags: branches, git, remotes
























Entries (RSS)
If you have Rubygems installed, you can install git_remote_branch to manage remote branches very easily
gem install git_remote_branch
grb track remote_branch
grb create remote_branch
grb delete remote_branch
grb rename remote_branch
Also, use “git remote prune origin” to refresh the remote branch list
[Reply]
Grrreat! This looks much more elegant.
[Reply]