Problem Description
I deleted this branch named "cert1", then added a branch with the same name and committed it (probably before pushing the delete action). Then, while trying to push this, I get this error -
! [rejected] cert1 -> cert1 (non-fast-forward)
Background
I am new to git.
I am trying to use git with phing. I am doing a POC where I am using the production server as a git working copy. My build script runs git checkout/pull command depending on which branch my production is at, and which branch I am rolling out on production.
I am going through all the use cases that could appear. One such case is that of the production server being in the branch A (during last rollout). Then, before the next rollout, the branch A gets deleted (from the development environment), and one with the same name gets created again (I assume this is possible). What if this is now needed to be rolled out now. Will I need to do a checkout now?
Normally, pushes are fast-forward because the remote history should be a prefix of the local history, and the remote will by default reject pushes until this is true. That is the behavior you are seeing when the remote rejects your push. The normal correction is to pull first and then push, so that the remote history becomes a prefix of your history.
In your case, the histories for the two branches may be entirely different after deletion and re-creation, and you must do a force push (git push -f
) to overwrite the remote history if that is what you are trying to do.
However, you must make sure you actually want to completely overwrite the remote branch's history and make it the same as your own; otherwise you should not do this.
An equivalent solution is to delete the remote branch manually before pushing
git push origin :cert1 # Delete the remote
git push origin cert1