0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Gitコマンド早見表

Posted at

Gitコマンド早見表

Gitを使ったソース管理における基本から応用まで、よく使うコマンドをまとめました。Qiitaなどで手元に置いておくと便利です。


初期設定

コマンド 説明
git config --global user.name "名前" ユーザー名の設定
git config --global user.email "メール" メールアドレスの設定
git config --global core.editor vim デフォルトエディタを指定
git config --list 設定の一覧表示

リポジトリ操作

コマンド 説明
git init 新しいGitリポジトリを作成
git clone <URL> リモートリポジトリを複製
git remote -v リモートリポジトリの確認
git remote add origin <URL> リモートリポジトリの追加

ステージ・コミット

コマンド 説明
git status 作業ディレクトリの状態確認
git add <file> ファイルをステージに追加
git add . すべての変更をステージに追加
git commit -m "メッセージ" コミットを作成
git commit --amend 直前のコミットを修正

ブランチ操作

コマンド 説明
git branch ブランチ一覧表示
git branch <name> 新しいブランチを作成
git checkout <name> ブランチを切り替え
git checkout -b <name> 新しいブランチを作成して切替
git merge <branch> 指定ブランチを現在にマージ
git branch -d <name> ブランチを削除

プッシュ・プル・フェッチ

コマンド 説明
git push origin main リモートにプッシュ
git push -u origin main 初回プッシュ + トラッキング設定
git pull origin main リモートからプル
git fetch リモートの最新情報を取得

差分とログ

コマンド 説明
git diff 作業ツリーとインデックスの差分
git diff --cached インデックスとHEADの差分
git log コミット履歴
git log --oneline 簡潔な履歴
git show <commit> 指定コミットの詳細

リセットと復元

コマンド 説明
git checkout -- <file> ファイルの変更を取り消す
git reset HEAD <file> ステージの取り消し
git reset --hard HEAD 全ての変更を取り消して戻す
git revert <commit> 指定コミットを打ち消すコミット作成

stash(退避)

コマンド 説明
git stash 変更を一時退避
git stash list stash一覧表示
git stash apply 退避を適用(保持)
git stash pop 退避を適用して削除

その他便利コマンド

コマンド 説明
git tag <tagname> タグをつける
git clean -fd 未追跡ファイル・ディレクトリ削除
git blame <file> 各行のコミット履歴を表示

Git初心者向けTips

  • .gitignore ファイルで追跡除外を設定できる
  • git log --graph --oneline --all は履歴を視覚的に見たいときに便利
  • GUIクライアント(Sourcetree, GitKraken, GitHub Desktop)も併用すると学びやすい

最後に

他にも便利なコマンドがあれば、ぜひコメントで共有してください!このチートシートは随時アップデート予定です。

0
1
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
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?