基本操作
-
git init
: 新しいGitリポジトリを作成する -
git clone <repository>
: 既存のリポジトリをクローンする -
git add <file>
: ファイルをステージに追加する -
git commit -m "message"
: 変更をコミットする -
git status
: ワーキングディレクトリの状態を表示する -
git log
: コミット履歴を表示する -
git diff
: 変更内容を表示する -
git rm <file>
: ファイルを削除し、削除をステージに追加する
ブランチ操作
-
git branch
: ブランチを表示する、作成する、削除する -
git checkout <branch>
: ブランチを切り替える -
git merge <branch>
: ブランチをマージする -
git rebase <branch>
: ブランチをリベースする -
git branch -d <branch>
: ブランチを削除する -
git switch <branch>
: 新しいブランチに切り替える(checkout
の代替)
リモートリポジトリ操作
-
git remote
: リモートリポジトリを表示する、追加する、削除する -
git fetch
: リモートリポジトリからデータを取得する -
git fetch
-p: リモートリポジトリからデータを取得し、存在しないリモート追跡ブランチを削除する -
git pull
: リモートリポジトリからデータを取得してマージする -
git push
: ローカルのコミットをリモートリポジトリに送信する -
git remote add <name> <url>
: 新しいリモートリポジトリを追加する
ステージとコミットの操作
-
git reset
: ステージやコミットをリセットする -
git revert <commit>
: 特定のコミットを打ち消す新しいコミットを作成する -
git commit --amend
: 直前のコミットを修正する -
git reset --hard <commit>
: 指定したコミットにハードリセットする
便利なツールとその他のコマンド
-
git stash
: 変更を一時的に保存する -
git stash apply
: 一時保存した変更を適用する -
git stash pop
: 一時保存した変更を適用して削除する -
git cherry-pick <commit>
: 特定のコミットを現在のブランチに適用する -
git tag
: タグを操作する -
git archive
: リポジトリ内容をアーカイブする -
git bisect
: バイナリサーチを使ってバグを探す -
git blame <file>
: 各行の変更者を表示する -
git clean
: ワーキングディレクトリをクリーンアップする
設定と情報
-
git config
: Gitの設定を操作する -
git show
: オブジェクト(コミット、ツリーなど)の詳細情報を表示する -
git describe
: 最も近いタグ情報を表示する
コラボレーション
-
git submodule
: サブモジュールを管理する -
git worktree
: 複数のワーキングディレクトリを管理する