リモートブランチとローカルブランチの追跡(tracking)を行っておくことで、gitコマンドの省略ができます。
省略例
- git pull origin ${branchName} -> git pull
- git push origin ${branchName} -> git push
- git fetch origin -> git fetch
追跡設定方法
- git checkout ${branchName}
リモートで新規に作成したブランチをローカルに落として来る際に、checkoutを行うと下記の表示のようにoriginから落としてきて、追跡を設定しました。
と出ます。(git fetchしてからでお願いします。)
Branch 'test' set up to track remote branch 'test' from 'origin'.
Switched to a new branch 'test'
- git push --set-upstream origin test
pushのタイミングで--set-upstream
オプションにより追跡を設定します。
ローカルで新規に作成したブランチをgit push
すると下記のように表示され、追跡を促進されています。
fatal: The current branch test-t has no upstream branch.
To push the current branch and set the remote as upstream, use
git push --set-upstream origin test
git pull origin ${branchName} ,git push origin ${branchName}
としていると意外と気づかない省略方法です。
追跡に関しては、参考資料を参照してください。
加えて
gitコマンドの省略も行うととても強力になります。
例
-
gf
(git fetch) -
gc ${branchName}
(git checkout) <- ブランチのTAB保管の設定が必要です。,gp
(git pull) - 作業
-
gs
(git status),gl
(git log option) -
ga .
(git add) -
gco -m "commit message"
(git commit) -
gpu
(git push)