I did:
git co upstream/master # To no branch.
<then did a trivial edit on some file...>
git commit -a -m "Trivial edit"
git push origin NewBranch
But got this:
$ git push origin ignore-netbeans-config
error: src refspec ignore-netbeans-config does not match any.
Can I push to a new branch without creating a local one?
Let's clear up a few small details first:
refs/heads
namespace. Justls .git/refs/heads
andcat
the files there to see what I mean.refs/tags
namespace. Just ls.git/refs/tags
to see for yourself.HEAD
just another "ref", but it's special in the aspect that it can be "symbolic". Justcat .git/HEAD
and see what it says.A
push
operation operates on a "ref", and the default "mapping" preserves the namespace. This means that when I push a branch, it'll appear as a branch on the remote; when I push a tag, it'll appear as a tag on the remote. Consider the following scenarios:I want to push the tag
moo
and make it appear as a branch on the remote server (yes, I'm essentially "converting" a tag into a branch). This is how I'll do it:git push origin moo:refs/heads/moo
Git needs a way to differentiate between fast-forward and non-ff pushes, so that people don't end up overwriting other people's work by mistake. Let's say I want to push the branches
master
,next
, andpu
, of which onlypu
is non-ff. This is how I'll do it (note that you must supply an explicit mapping when you're using+
):git push origin master next +pu:pu
Now, let's get to your question. You want to push your
HEAD
so that it appears in therefs/heads
namespace on the remote as a branch named "ignore-netbeans-config". If this branch didn't exist before, or if you're overwriting some commits in it (ie. non-ff push), use the+
. Otherwise, don't. End result:git push origin +HEAD:refs/heads/ignore-netbeans-config
TL;DR version:
git push origin +HEAD:refs/heads/ignore-netbeans-config