git create remote branch

How to Create Remote Git Branch

Sometimes you may need to create remote git branch for your project. In this article, we will learn the steps to create remote git branch.


How to Create Remote Git Branch

Here are the steps to create remote git branch.


1. Create Local Branch

First, navigate to your git repository folder and run the following command to create a local git branch. Replace branch_name with the name of your branch. The following command will create branch and check it out.

$ git checkout -b branch_name

Here is an example to create data branch.

$ git checkout -b data


2. Push Local Branch to Remote Server

Next, run the following command to push local branch to remote server.

$ git push remote_name branch_name 

Typically, remote_name is origin, the default name given to remote repository. Here is an example to push data branch to remote repository.

$ git push origin data

In the remote repository, git will create a new branch with the same name as the local one, and push its contents to the remote branch.

The above command is a shorter version of the actual command

$ git push remote_name local_branch_name:remote_branch_name

Here is an example.

$ git push origin data:data

Please ensure you do not mention only :remote_branch_name in the above command, otherwise git will delete the remote branch.


3. Set upstream branch

You might also set an upstream branch to make it easy for others to pull. Here is the syntax.

$ git push --set-upstream remote_name local_branch_name 

When you set an upstream branch, git will set a remote branch for the given local branch. Otherwise, every pull command will set the master as your default remote branch and you will need to specify the target remote branch’s location with respect to master (e.g. git pull origin/data instead of git pull).

That’s it. In this article, we have learnt how to create remote git branches. You can customize these commands as per your requirement.

Also read:

How to Unstage Files in Git
How to Enable Bluetooth from Command Line
How to Add Repository in Ubuntu
How to Delete Folders Older Than 7 Days
NGINX Prevent Host Header Attack

Leave a Reply

Your email address will not be published.