in Technology by
How can we create a remote Git branch?

1 Answer

0 votes
by

First, create your branch locally:

git checkout -b <branch-name> # Create a new branch and check it out

The remote branch is automatically created when you push it to the remote server. So when you feel ready for it, you can 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.

Note however that formally, the format is:

git push <remote-name> <local-branch-name>:<remote-branch-name>

But when you omit one, it assumes both branch names are the same. Having said this, as a word of caution, do not make the critical mistake of specifying only :<remote-branch-name> (with the colon), or the remote branch will be deleted!

So that a subsequent git pull will know what to do, you might instead want to use:

git push --set-upstream <remote-name> <local-branch-name> 

As described below, the --set-upstream option sets up an upstream branch:

For every branch that is up to date or successfully pushed, add upstream (tracking) reference, used by argument-less git-pull(1) and other commands

Related questions

0 votes
    How can we check out a remote Git branch?...
asked Jan 7, 2021 in Technology by JackTerrance
0 votes
    How can we create a new branch on both local and remote?...
asked Jan 8, 2021 in Technology by JackTerrance
0 votes
    I created a local branch that I want to 'push' upstream. There is a similar question here on Stack ... the upstream repository? Select the correct answer from above options...
asked Feb 2, 2022 in Education by JackTerrance
0 votes
    How to rename and remove branch in remote Git?...
asked Aug 24, 2021 in Technology by JackTerrance
0 votes
    How to push a new local branch to a remote Git repository and track it too?...
asked Jan 7, 2021 in Technology by JackTerrance
0 votes
    we are using git in Team Foundation Service, and we are trying to find a way to delete a remote ... /DefaultCollection/_git/Xxxxxx' Select the correct answer from above options...
asked Feb 1, 2022 in Education by JackTerrance
0 votes
    How can we rename a local Git branch?...
asked Jan 7, 2021 in Technology by JackTerrance
0 votes
    What is the Git command to create a branch? A. git invoke branch branchname B. git add branch branchname C. git create branch branchname D. git branch branchname...
asked Dec 20, 2022 in Technology by JackTerrance
0 votes
    How to Reset local repository branch to be just like remote repository HEAD?...
asked Jan 7, 2021 in Technology by JackTerrance
0 votes
    Can you recover a deleted branch in Git?...
asked Nov 4, 2020 in Technology by JackTerrance
0 votes
    What is the command to delete a branch in your remote repository? A. git delete branchname B. git branch -d branchname C. git push origin -d branchname D. None of the options...
asked Dec 20, 2022 in Technology by JackTerrance
0 votes
    What is the command to delete a branch in your remote repository? (1)git branch -d branchname (2)None of the options (3)git push origin -d branchname (4)git delete branchname...
asked Oct 26, 2020 in Technology by JackTerrance
0 votes
    What is the command to delete a branch in your remote repository? (1)git branch -d branchname (2)None of the options (3)git push origin -d branchname (4)git delete branchname...
asked Oct 26, 2020 in Technology by JackTerrance
0 votes
    How can we stash only one of multiple changed files on my branch?...
asked Jan 8, 2021 in Technology by JackTerrance
0 votes
    I pulled a project from GitHub a few days ago. I've since discovered that there are several forks on GitHub, ... those forks I pulled? Select the correct answer from above options...
asked Feb 2, 2022 in Education by JackTerrance
...