Branching makes efficient ways to manage versioning of your application code. The popular version management tools supported branches like Git, SVN etc. Development in branching make process easier by splitting code in branches per modules.

Advertisement

Most of the Git providers (like: github.com, gitlab.com etc) provides option to create branch directly with web interface. But, in case you don’t have web interface access, You can also do the same by creating a branch in local repository and push changes to remote.

This article will help you to create a branch on local repository and then push branch to the remote Git repository.

Create A Local Git Branch

First create branch on local git repository using following command. This command will create a branch named “stage1” and switch to it immediately.

  • Syntax:
    git checkout -b <BRANCH_NAME> 
    
  • Command:
    git checkout -b stage1 
    

You can created a branch on your local git repository. Use git branch command to view all the branches in local repository.

Push Branch to Remote Git Repository

Now push newly created branch to remote Git repository. Branch will automatically created on remote git repository.

  • Syntax:
    git push <REMOTE_NAME> <BRANCH_NAME>
    
  • Command:
    git push origin stage1
    

The above command creates branch on remote git repository with same name as local “stage1” and push all files there.

You can also create branch on remote branch with other name. To create remote branch with other name speicify the remote branch branch name just after local branch name seprated with colon (:). The syntax and command looks like below:

  • Syntax:
    git push <REMOTE_NAME> <LOCAL_BRANCH_NAME>:<REMOTE_BRANCH_NAME> 
    
  • Command:
    git push origin stage1:development 
    

This will create branch named “development” on remote git repository and push data from local branch “stage1

Conclusion

In this tutorial, you have learned to create a branch on remote git repository.

Share.

Leave A Reply