Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git: how to turn a clone into a new branch? [duplicate]

Tags:

git

I've cloned master from my repository and have been making a bunch of edits and local commits. I've now realised this should be a new branch in my remote repository. Normally I'd just push to the remote system, how do I push as a new branch to the remote repos?

like image 538
new299 Avatar asked Feb 08 '13 16:02

new299


People also ask

How do I copy a clone to another branch?

In order to clone a specific branch, you have to execute “git branch” with the “-b” and specify the branch you want to clone. $ git clone -b dev https://github.com/username/project.git Cloning into 'project'... remote: Enumerating objects: 813, done.

Does git clone make a new branch?

git clone --single-branch : By default, git clone will create remote tracking branches for all of the branches currently present in the remote which is being cloned. The only local branch that is created is the default branch.

Can I clone the same repository twice?

Simply clone your project's repo twice (or even more often). When your work on a feature branch is done, simply push that branch and check it out on your 2nd copy to run tests there. You can pick up a new story and work on that on your "main" project directory.


1 Answers

Assuming you have't pushed anything yet and your history looks something like

A -- B -- C -- D -- E
^                   ^
|                   |
origin/master       master

You can just do the following:

git branch feature
git reset origin/master

to get this:

A -- B -- C -- D -- E
^                   ^
|                   |
|                   feature
origin/master,master
like image 99
chepner Avatar answered Oct 24 '22 06:10

chepner