How to git force good
A very common statement that’s made:
Git force push is bad
This statement lacks a lot of context and paints a wrong statement.
How to git force push
To do a git force push use the flag — force
or -f
with the git push
command.
(This assumes the “upstream” is already set for the git branch)
This essentially rewrites remote history.
Hold on! Do go through the next section to understand how to effectively use this tool.
How to git force push good
More often that not the discussion has happened how git force push is bad and looked upon. Although like any other tool, it’s about knowing what to use when to use.
My takes is as below:
- It’s fine to use it on a branch as long as you deem the history rewrite is totally safe.
Force pushing is fine as long as you know what you are doing i.e you are very well aware of the consequences - which here in case is rewriting remote history. If your context declares that is an OK decision to make then nothing to worry about.
Things to know
-
Don’t force push to collaborative branches without consent from all collaborators.
-
Force pushing to private branches is fine - given you are the only person working on that branch.
-
Force pushing to branches that are meant to be destructive and doesn’t contribute to code history is also fine.
All in all force push is a nifty feature, it’s like saying a knife is dangerous. It’s not the knife that is dangerous it’s the intent of the person holding it is.
Notes
Rewriting remote history: What it means is that the chain of commits that are there in remote will be overwritten by the chain of commits that you have in your local machine. This is a destructive action, meaning it will make changes that are not recoverable (easily).
Updated on