I'd like to create a new remote branch for later use. The most commonly suggested way seems to be:
git checkout -b newbranch origin/startingpoint
git push origin newbranch
But this will also create the branch locally and put me on it. Is there a way of creating a remote branch without creating it locally and moving onto it?
I would like to make twalberg's comment an answer. You can create a remote branch by adding
refs/head/
to it:As torek explains,
git push
addsrefs/heads/
automatically if you have a local branch. If you don't have a local branch, it doesn't know if you want to push torefs/heads/
or torefs/tags/
. My version of git says: "we are unable to guess a prefix based on the source ref". By addingrefs/heads/
you tell git to create a branch on the remote, not a tag.push demands a local ref, though it seems to me now that's a bit arbitrary. But it doesn't care what the local ref is called, you can say what remote name you're pushing to directly, so: