I ran into a similar problem after renaming a local instance of a new and recently pulled branch from develop
to origin-develop
. The branch was fetched from the remote repo origin
.
After the rename, a generic push commands I gave would always try to push to origin/master
. i.e.,
$ git push
To github.com:<USER>/<REPO>.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'github.com:<USER>/<REPO>.git'
I tried using git branch origin develop
, but that didn't fix the problem. Instead, I got the error
$ git push origin develop
error: src refspec develop does not match any
error: failed to push some refs to 'github.com:<USER>/<REPO>.git'
Using the command git remote show origin
allowed me to see that the while the local branch origin-develop
was set up correctly for pulling (presumably because I created the local branch using the pull command), it was missing the push setting.
Local branches configured for 'git pull':
<snip>
origin-develop merges with remote develop
<snip>
Local refs configured for 'git push':
<snip>
I was able to fix my problem by using the command
git push origin origin-develop:develop
This worked, but I don't consider it solved because I have to use this command every time I want to push this branch to the remote. If I just use git push
I get the ! [rejected] master -> master (non-fast-forward)
error.
My understanding is that my pull
command set up the remote for pulling, but not pushing. Because no remote push was defined, it defaulted to pushing to master
.
What I don't understand is how to permanently change my configuration so that git push
works as expected. I've tried using git branch -u
, but get the same behavior (i.e. can't push). I wonder if somehow the push -all
option is now the default and the error message is independent of the branch origin-develop
.