Home » Source Code Management ( SCM ) » Git » How to Create a Remote Branch in Git ?

How to Create a Remote Branch in Git ?

The process to create a new branch a remote git starts with having this git on your local machine, so lets first clone the git. As an example, we are cloning our repository from GitHub. You have to use yours.

$ git clone https://github.com/lynxbee/git-helloworld.git
$ cd git-helloworld/

Check what is the default branch in cloned local code,

$ git branch
* master

Check which all branches are available in remote git repository, this can be done using “git branch -r” command,

$ git branch -r
  origin/HEAD -> origin/master

Now, lets say we want to create a new branch in remote git, which is based on our current cloned branch. So, in our current code the active branch is “master” so we will create branch “new_branch” with master as base branch.

$ git branch new_branch

switch to this new branch,

$ git checkout new_branch

Now, push the code to remote git with “new_branch” as second argument, so the below command will create a new branch in remote git and also push the code to this newly created branch.

$ git push origin new_branch

Now, you can check the newly created branch in remote git as,

$ git branch -r

Leave a Comment