What is the difference between force push and normal push, and in what kind of situations should I force push in git? Is it good practice to force push into the master branch?
You only force a push when you need to replace the remote history with your local history.
This happens when you rewrite the local history, typically through a git rebase
.
For instance, if you just pushed an incorrect commit, and amend it locally, using a push --force
can help correct a recent push.
If you are the only one working on the branch you are force pushing, this is not a big deal. If you are not the only one, then you need to communicate clearly in order for other users to reset their own local branch to the new remote. Or you need to avoid force pushing in the first place.
Is it a good practice to do force push into master branch?
Generally, it is not a good practice (again unless you are the only one using the remote repo). And don't forget that once a branch has been force pushed... you cannot know who did the push --force
.