Git is driving me nuts, how can I create a new remote branch based on an existing non-master branch?
I'm sure this is very simple to do, but I have followed a number of tutorials and cannot figure this out.
I currently have two branchs on my remote & local machines:
master
*search_refactor
We want to create a new remote branch called design_refactor and have the code in this new br开发者_运维知识库anch to be (initially) a clone of the code in the search_refactor branch.
The purpose behind all of this is that I want to try out some ideas I have on the search_refactor branch, share these with others, but not modify the search_refactor branch.
Our current version of git is 1.6.5
Thanks!
To make a new branch on the remote, you can create it by pushing to the new reference. E.g.
git push origin search_refactor:refs/heads/design_refactor
This pushes that state of the local search_refactor
branch as the new remote design_refactor
branch.
IIRC you need the refs/heads
to bypass a safety check that git needs the branch to already exist or for you to be pushing a matching named local branch.
If you wanted to use the state of the remote search_refactor
branch, without any changes that you might have in your local search_refactor
branch you could use:
git push origin origin/search_refactor:refs/heads/design_refactor
Once you've done this you can checkout a new local branch based on the remote branch.
git checkout -b design_refactor origin/design_refactor
(For simplicitly I've assumed that your main remote is called origin
.)
精彩评论