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.
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'...
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With