2017-09-12 7 views
0

私は、上流のブランチのないリモートのリポジトリ(例えばGitHub)にプッシュするときにエラーを防ぐためのBash関数を持っています。おそらくあなたは、このエラーに精通している:git config push.default currentに切り替えることの意義は何ですか?

$ git checkout -b test 
$ git push 
fatal: The current branch test has no upstream branch. 
To push the current branch and set the remote as upstream, use 

    git push --set-upstream origin test 

、その修正私がやっていることはgit pushへの呼び出しを傍受し、ノー上流分岐に関連するエラーを取得していますかどうかを確認します。そのエラーの場合は、上記のコマンドをコピー&ペーストするのではなく、私の端末で自動的に実行されます。

あなたが興味がある場合、これはコードです: https://github.com/arturoherrero/dotfiles/blob/6f517a0b7287ac61174dfd2b6c9ee5bf9a9c2e96/system/git.sh#L22-L34


私の現在のGitの設定がpush.default simpleですが、今日、私はちょうど私が削除(同じ動作を達成するためにpush.default currentを使用することができますことに気付きました私のカスタムコード)。

Ref。 https://www.kernel.org/pub/software/scm/git/docs/git-config.html

  • current - push the current branch to update a branch with the same name on the receiving end. Works in both central and non-central workflows.

  • simple - in centralized workflow, work like upstream with an added safety to refuse to push if the upstream branch’s name is different from the local one.

    When pushing to a remote that is different from the remote you normally pull from, work as current. This is the safest option and is suited for beginners.

    This mode has become the default in Git 2.0.

ので、git config push.default currentへの切り替えの意味は何ですか? Gitの動作が異なるため、問題が発生する可能性のあるシナリオをいくつか理解したいと思います。

答えて

2

これは、リポジトリにプッシュすると、gitはブランチ名が対応しているとみなします。単一のリモート(origin)にプッシュするだけで、リモートとローカルの同じブランチに同じ名前を使用すると、問題ありません。他のタイプのブランチマッピングを設定する場合は、たとえば、ローカル機能ブランチfeature_1をリモートブランチdev/features/feature_1またはそのようなものにする必要がある場合は、push.defaultとしてsimpleを使用することは望ましくありません。

実際に隠された意味はありません。あなたが投稿したドキュメンテーションはその動作を説明し、それがあなたが望む動作であればそれを使うことができます。

関連する問題