Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a new branch on both local and remote? GIT [duplicate]

I create a new branch like this:

 git branch dev-itt-9 

However, it only creates a new branch on local

 git branch -a  * dev-itt-9   master   testing    remotes/origin/HEAD -> origin/master   remotes/origin/development   remotes/origin/master   remotes/origin/testing 

What is the proper way to create a new branch on both local and remote?

I am quite new to git. Sorry if my question is stupid.

like image 427
chipbk10 Avatar asked Nov 05 '15 13:11

chipbk10


People also ask

Can I duplicate a branch in git?

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'...

How do I copy a local branch to a remote branch?

If you have a single remote repository, then you can omit all arguments. just need to run git fetch , which will retrieve all branches and updates, and after that, run git checkout <branch> which will create a local copy of the branch because all branches are already loaded in your system.

How do you create a new branch that tracks remote branches?

To create a new local branch based on a remote branch, use the "-track" option in the branch command. You can also do this by using the "checkout" command. If you want your local branch to have the same name as the remote branch, you only need to specify the name of the remote branch.


1 Answers

First, you create your branch locally:

git checkout -b <branch-name> 

The remote branch is automatically created when you push it to the remote server. So when you feel ready for it, you can just do:

git push <remote-name> <branch-name> 

Where <remote-name> is typically origin, the name which git gives to the remote you cloned from. Your colleagues would then just pull that branch, and it's automatically created locally.

Credit: this answer is a copy of https://stackoverflow.com/a/1519032

like image 119
Deepak Biswal Avatar answered Sep 23 '22 05:09

Deepak Biswal