Git:-uフラグが欠落してプッシュが失敗した後のプロンプトの自動補完

Git:-uフラグが欠落してプッシュが失敗した後のプロンプトの自動補完

gitを使用すると、ローカルブランチを作成してからリモート(Githubなど)にプッシュすることがよくあります。これには、-uまたは--set-upstreamフラグが必要です。

gitこのフラグのない出力は次のとおりです。

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

    git push --set-upstream origin newbranch

この提案を私のメッセージにコピーする方法はありますか?これにより、入力する必要はありません。それは次のとおりです。

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

    git push --set-upstream origin newbranch

$ <tab>
$ git push --set-upstream origin newbranch

ベストアンサー1

現在のブランチをリモートでプッシュするようにエイリアスを設定できます。

次のコマンドを使用してエイリアスを設定します。

git config --global alias.rpush '!git push --set-upstream origin $(git rev-parse --abbrev-ref HEAD)'

このgit rev-parse --abbrev-ref HEADコマンドは現在のブランチの名前を返します。次に実行します。

git rpush

必要に応じて別名に別の名前を付けることができます。

おすすめ記事