I hear that force pushing (git push -f) is a dangerous practice to be avoided if possible. That being said, what would be a safe procedure for doing so in the case of a private repo shared among a small team? I imagine it would be something like this:
Can someone complete this procedure or scrap it and offer a better one? I'm looking for the simplest safe procedure.
You can do git push --force-with-lease
It will push your changes only when the remote branch is in the same state in the remote as you can see it locally.
See https://git-scm.com/docs/git-push#git-push---no-force-with-lease for more details.
The following approach looks kind of fragile but will work assuming all other team members don't have any local commits on the said branch.
You add code to the branch and push force it (steps 1-5 in your question):
git checkout feature
# Add code
git push --force-with-lease
Other developers on your team should do the following (Step 6):
git fetch
git branch -D feature
git checkout feature
After this has been executed, all team members will have the exact same branch as you.
If any of them had any non-pushed commits, they will be lost!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With