Reputation: 4229
Something I've seen "hammered in" repeatedly is that one should not ever git push --force
, though surely there are times when it is appropriate?
When is --force intended to be used?
My current example:
Is push --force the appropriate solution to this?
Upvotes: 1
Views: 327
Reputation: 9473
push -f
becomes really necessary if you need to remove some sensitive data from the repo which you have mistakenly pushed. In that case you'll need to do a git filter-branch
and git push -f
. This article explains the process.
Also, I've come across instances when you need to do push -f
when a junior developer has done something stupid with the repo. Anyway, one shouldn't have given them the rights in the first place or given them adequate training.
Upvotes: 2
Reputation: 4503
Rewriting history will be a headache for anyone who pulled your repo and made their own changes based on your branches. When you rewrite your remote history and the downstream people pull it, their changes will end up dangling off in the middle of nowhere. (Check out the Recovering from an upstream rebase section of the git rebase
docs.)
That's why if other people are using your repo, it would generally be better to merge changes from origin into live
and push the merge. It's not as clean as a rebase, but no one downstream will need to do funky things to keep up with your rewrites:
git checkout live
git merge --no-ff origin/whatever
git push origin live
You can always rebase when you're ready to pull the changes in live
back into the main branch.
On the other hand, if you're the only one using your repo, or the people downstream are ok with fixing remote history rewrites, --force
away.
Upvotes: 1
Reputation: 18706
I usually push -f
right after the initial push, when I know that no one has fetched my changes yet, or when I'm the only one working on the project.
Otherwise, as long as you rewrite the history, you should avoid forced pushes.
Upvotes: -1
Reputation: 44515
In that case yes, assumed that you're the only one who works on that branch, or that others understand the implications, when you do a forced push and rewrite the history of that feature branch.
Upvotes: 2