LoginSignup
1
2

More than 5 years have passed since last update.

よく使うGitコマンド

Posted at

これだけ覚えときゃ仕事でなんとかなる。オレの場合は。

ブランチの確認

  • ローカルのブランチ確認
git branch
  • リモートのブランチ確認
git branch -r
  • 追跡中のブランチ確認
git branch -vv

ブランチの作成

  • カレントブランチからブランチを作成
git checkout -b branch_name
  • リモートからクローンしてブランチを作成
git checkout -b branch_name origin/branch_name

ブランチの切り替え

git checkout branch_name

指定したファイルのチェックアウト

git checkout コミットID path

pathにファイルのパスを指定すると、そのファイルだけチェックアウトできる。

pathにディレクトリを指定するとそのディレクトリ配下のファイルを全てチェックアウトできる。

git logをツリー表示

  • コミットID省略版
git log --graph --pretty=format:"%h %cd %s"
  • コミットID全表示版
git log --graph --pretty=format:"%H %cd %s"
  • 変更したファイルを表示
git log --name-status

ファイルのステージング

git add .

コミット

  • 普通のコミット
git commit
  • ブランチを作った直後に初期コミット
git commit --allow-empty

プッシュ

  • 追跡中ブランチへのプッシュ
git push
  • カレントブランチ名と追跡中ブランチ名が異なる場合のプッシュ
git push origin current_branch_name
  • リモートのカレントブランチを追跡するようにさせつつプッシュ
git push -u origin current_branch_name

ブランチの削除

  • 安全な削除
git branch -d branch_name
  • 強制削除
git branch -D branch_name

マージ

branch_nameのブランチをカレントブランチにマージする

git merge branch_name

リモートの変更の取り込み

git pull
1
2
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
1
2