Quantcast
Channel: When should I use "git push --force-if-includes" - Stack Overflow
Viewing all articles
Browse latest Browse all 7

Answer by Devin Rhode for When should I use "git push --force-if-includes"

$
0
0

Make force push safer

You may use git exclusively through the cli, but, some editors (like vscode), it will automatically run git fetch every 2 minutes in the background, and show you if there are new commits to pull down.

If you want safer force pushing, you'll need to disable auto-fetching inside your editor.

First, it's a good idea to force push through the gui, because it uses very explicit syntax:

vscode git gui extension push/pull dropdown menu "force push" option

vscode runs this under-the-hood:

git push --force-with-lease origin feature/foo:feature/foo

You can influence this call with the git config option push.useForceIfIncludes:

[push]  useForceIfIncludes = true

You can combine this with disabling auto-fetching in vscode:

"git.autofetch": false,

This would then cause force pushes through vscode's gui menu to fail unless you explicitly run git fetch or git pull or git pull --rebase before hand.

A gui could make this even safer, doing things like:
- show the diff between your local branch and the remote branch
- show diff of log, allowing you to see which shas/commits will be obliterated, and what they will be replaced with
- tell you if force push is even necessary
- implement *even safer* checks

Viewing all articles
Browse latest Browse all 7

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>