Marco Merlini
Marco Merlini

Reputation: 3

Can't push branch A because failed to push refs on branches B, C, D,

Consider the following interaction I've just had with git:

$ git branch
* branch_A
  branch_B
  branch_C

$ git push
To [email protected]:repo.git
 ! [rejected]        branch_B -> branch_B (non-fast-forward)
 ! [rejected]        branch_C -> branch_C (non-fast-forward)
error: failed to push some refs to '[email protected]:repo.git'
hint: Updates were rejected because a pushed branch tip is behind its remote
hint: counterpart. Check out this branch and merge the remote changes
hint: (e.g. 'git pull') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

I have not touched branches B or C since I last pulled them (though the remote has been updated). No one else has touched the remote branch A, which is my personal feature branch. Also, my local branch A does not have a divergent history; it's just one commit ahead of the remote branch A.

Why is this happening? How do I get around it?

Upvotes: 0

Views: 70

Answers (1)

tmaj
tmaj

Reputation: 35037

It looks like your git is set up to push all local branches when you do a push. That's OK.

I'd take the situation step by step and approach it systematically.

Git tells us that there is something not right with braches B and C. If you don't care about them you can delete them, but a safter way is to check them and do a git pull.

Option A - pull B and C

If yod didn't change B or C then something like this should allow you to push A.

git checkout branch_B
git pull
git checkout branch_C
git pull
git checkout branch_A
git push

Option B - delete local B and C

git branch -D branch_B branch_C (please note capital D)
git push

If you need B and C after that you just check them out again.

Upvotes: 1

Related Questions