www.question-defense.com | Engage: Visit :: Login :: Register
Translate to English Übersetzen Sie zum Deutsch/German Переведите к русскому/Russian Μεταφράστε στα ελληνικά/Greek Vertaal aan het Nederlands/Dutch ترجمة الى العربية/Arabic 中文翻译/Chinese Traditional 中文翻译/Chinese Simplified 한국어에게 번역하십시오/Korean 日本語に翻訳しなさい /Japanese Traduza ao Português/Portuguese Traduca ad Italiano/Italian Traduisez au Français/French Traduzca al Español/Spanish
0

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.

DeliciousStumbleUponDiggTwitterMixxTechnoratiFacebookNews VineLinkedInYahoo! Bookmarks
Related posts:
  1. 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...
  2. How To Switch Between Git Branches From The Linux CLI If you are using Git for version control then it...
  3. Delete a Remote Branch from GitHub Deleting a remote branch from a GitHub account is easy...
  4. msysgit clone Error – fatal: Cannot update the ref ‘HEAD’ I wanted to start syncing a git project to my...
  5. TortoiseSVN: Update Local Repository for a Remote Repository That Has Moved If you have been working on a project that is...

Tags: , ,
2 Responses to “Creating remote branches from local ones in Git”
  1. Chirag Patel says:

    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]

  2. derek says:

    Grrreat! This looks much more elegant.

    [Reply]

  3.  
Leave a Reply