LoginSignup
3
3

More than 5 years have passed since last update.

git 追跡によるコマンドの省略

Posted at

リモートブランチとローカルブランチの追跡(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コマンドの省略も行うととても強力になります。

  1. gf(git fetch)
  2. gc ${branchName} (git checkout) <- ブランチのTAB保管の設定が必要です。, gp(git pull)
  3. 作業
  4. gs(git status), gl(git log option)
  5. ga .(git add)
  6. gco -m "commit message"(git commit)
  7. gpu(git push)
3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3