How to create a new branch on both local and remote? GIT
GitGithubVersion ControlGit BranchGit Problem Overview
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.
Git Solutions
Solution 1 - Git
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
Solution 2 - Git
Suppose you already created your local branch (using git branch <branch-name>
or git checkout -b <branch-name>
, you can use:
git push -u origin <branch-name>
explications:
-u
=--set-upstream
: set this new remote branch as tracking branch.origin
: the name of your remote repository