I have a local branch foo
which is set up, I thought, to track remote branch PROJ-123-foo
.
But when I tried a simple
git push
on that branch, I got a fatal error:
fatal: The upstream branch of your current branch does not match the name of your current branch.
To push to the upstream branch on the remote, use
git push origin HEAD:PROJ-123-foo
To push to the branch of the same name on the remote, use
git push origin HEAD
This made no sense to me, because as I said, I thought my local branch was already indelibly associated with branch PROJ-123-foo
on the remote. I thought I had already set things up so that the local and remote branch names were different, i.e. so that git wouldn't think I wanted to "push to the branch of the same name on the remote".
I tried to confirm what remote branch name I had configured, but here I ran into further difficulties. I ran git help branch
without finding any useful options. I found the question Find out which remote branch a local branch is tracking, which seemed to be exactly what I was asking, but the answers there make no sense to me. In desperation I peeked at .git/config
, and found the lines
[branch "foo"]
remote = origin
merge = refs/heads/PROJ-123-foo
which seemed to confirm that the association was at least something like what I thought.
Next I noticed the text
To choose either option permanently, see push.default in 'git help config'.
at the bottom of the original error message. I feel really bad saying this, because someone was clearly trying to anticipate my needs there, and I appreciate that, but: the problem is that I don't understand the options available to me under push.default
, either.
So my questions are:
Was I wrong to imagine that local branches are always tied pretty firmly to remote branches, such that
git push
should always know exactly what to do?Is part of my problem that my local branch isn't tied firmly enough to my remote? I've heard that there are potentially two distinct remote associations; perhaps I'm missing the one for pushing?
Do I maybe want to set
push.default
toupstream
? The documentation says that's for a "central workflow". I'm not sure I know which workflow I think I'm using, but I think I thought it was closer to "flow". Nevertheless I do think that lots of my local branches are bolted1:1
onto same- or similarly-named branches in our gitlab server. I'm not sure how to convince myself thatupstream
is the right choice, that it doesn't have unsuspected downsides that might bite me later, that another choice might be better.If the answer is "just use
push.default = upstream
", is there a reason that's not the default? (I suspect I'm missing something.)Is there a better way to confirm (or set) remote branch associations, or should I just peek at the config file?