When you rebase commits that have already been pushed to a remote repository, you need to specify the force flag when you push your newly rebased branch up to the remote.
git push origin New_Design -f
Why this happens
Your remote branch looks like:
A - B - C - C1 - C2 - C3
Following the rebase, your local branch looks like:
A - B - C - D - E - C1' - C2' - C3' - C4 - C5 - C6
To git, this looks like you've removed the commits C1
, C2
, and C3
. In reality, the same (or very similar, unless you manually resolved conflicts) set of changes is contained in C1'
, C2'
, and C3'
, so you won't lose work in this case. Since git can't know for sure, it makes you verify that you really want to do this by requiring the -f
flag.
Force pushing can result in lost work on the remote branch in a variety of situations:
- If you have other people working on the remote repository and their changes aren't reflected in your local branch. Git is suggesting
git pull
to remedy this situation. - If you've rewritten history on your local branch and removed or changed commits.
Since you're working alone, you're safe to do a force push if you're happy with your local branch.