push --force-with-lease by default Ask Question

push --force-with-lease by default Ask Question

I just learned about git push --force-with-lease. It's pretty awesome. But, of course, I don't use force that often, and so I'm worried that I might forget about this nifty feature the next time I need it.

Is there a way to configure git so git push -f will automatically use --force-with-lease unless I intentionally override it with --no-force-with-lease?

(I can't imagine ever wanting to use force without lease!)

ベストアンサー1

There currently is no way to configure git to always use force-with-lease instead of force. As such the next best available option is, as so often, to create an alias which serves this purpose.

EDIT This is still true in May 2022. But git 2.30 added an additional option force-if-includes which makes force-with-lease even safer; checkout this in-depth answer if you want to understand the reasoning.

Create an alias

エイリアスを作成するには を使用しますgit config --global alias.<alias-name> <command>。このケースでは、これに似たものをお勧めします。

git config --global alias.pushfwl "push --force-with-lease"

これにより、グローバル.gitconfigファイル(通常はホームディレクトリ)。その後はgit pushfwl強制的にリースする

手を汚す

あるいは、この機能を自分で実装することもできます。どこから始めればよいかわからない場合は、ドキュメンテーションgitリポジトリ内のディレクトリ. ここでは、コーディングガイドラインおよび情報方法パッチを送信する

これらのリンクやその他のリンクは、公式コミュニティページ

おすすめ記事