0

step 1. git pull --rebase

step 2: git push origin my_branch

I get push failed error. If I push branch after removing remote branch then no error.

Question, how to push branch after pull rebase?

Thanks

  • Can you type `git branch -vv` and let us know what remote branch is being tracked by `my_branch`? Normally, you should not see such an error when rebasing on your own branch. – Tim Biegeleisen Nov 23 '16 at 10:54
  • One possibility is that someone made a new commit to `my_branch` between the time you rebased and the time when you tried to push. – Tim Biegeleisen Nov 23 '16 at 10:54
  • @TimBiegeleisen you right. I am rebasing from another branch and there are latest commits too. I am checking and will update you – Mike Andrew Nov 23 '16 at 10:59
  • Ok your answer was correct. Right now I tried git push --force origin my_branch and it worked without error. Thanks for your advice. – Mike Andrew Nov 23 '16 at 11:04
  • But beware...force pushing has consequences. – Tim Biegeleisen Nov 23 '16 at 11:06
  • Possible duplicate of [Git push rejected after feature branch rebase](http://stackoverflow.com/questions/8939977/git-push-rejected-after-feature-branch-rebase) – Tom Nov 23 '16 at 13:02

2 Answers2

1

Rebasing a branch in Git may involve rewriting the history of that branch, assuming that the bases of the two branches were different. From what you told us, it seems that you rebased on a different branch. Most likely, in your case, your my_branch was rewritten, which means you cannot simply push to the remote.

To get around this, you can force push your branch via:

git push --force origin my_branch

However, you might not want to do this if the rebase on a different branch were unintentional.

Instead, try rebasing this way:

git pull --rebase origin my_branch
# resolve merge conflicts, if any
git push origin my_branch

General warning:

Force pushing a public shared branch is usually a bad idea, because it causes problems for everyone who shares that branch. If your current workflow involves doing this, you might want to reconsider.

Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360
1

First of all you have to check the status of rebase process. If rebase is running push wouldn't work. So git rebase --abort/ git rebase --skip to stop the rebase. Then try to commit any untracked files if any mismatch.

Finally git push origin my_branch will work I think.