git pull 時に --set-upstream-to とか言われるのを回避するコマンドを作る
git pull した時に --set-upstream-to しろみたいなコメントが出て、git pull 出来ない時がある。
$ git pull
There is no tracking information for the current branch.
Please specify which branch you want to merge with.
See git-pull(1) for details
git pull <remote> <branch>
If you wish to set tracking information for this branch you can do so with:
git branch --set-upstream-to=origin/<branch> branch_name
恐らく以下の記事で触れた、git push 時の --set-upstream オプションを省くための作業を行ったことで、この問題が起こるようになったっぽい。
ローカルで新規ブランチを作り、初めて git push した直後に git pull すると、「どこのリモートブランチと紐付いてるのか分からん」と言われてしまうっぽい。
対処法としては、指示されているとおりの git branch --set-upstream-to コマンドを叩けば良いのだが、いちいちカレントブランチ名を入力しないといけないのが面倒臭い。
ということで、gplf (git pull force) というコマンドを作ってみた。git push --force があるんだから、git pull --force (とにかく Pull させろ) というコマンドがあってもいいじゃろ、ということで命名。w
#!/bin/bash
# git pull 時に --set-upstream-to しろというエラーが出た時に自動処理させる
# カレントブランチ名
current_branch_name="$(git rev-parse --abbrev-ref @)"
# リモートブランチを指定して git pull する
git branch --set-upstream-to="origin/${current_branch_name}" "${current_branch_name}"
git pull
このスクリプトを gplf という名前で保存し、PATH が通っているところに配置、$ chmod +x ./gplf と実行権限を付与すれば準備 OK。
僕は git pull を gpl とエイリアス登録しているので、gpl と入力して前述のエラーが出たら、gplf と打ち直してこのコマンドを実行させる、というワケ。
コレでもう --set-upstream-to エラーに対して手間をかけなくて済むぞい。