Git コマンド チートシート

Git はファイルの変更をリポジトリ内の一連のコミットとして記録します。これらのコマンドは日々の流れ——リポジトリの作成、作業の保存、ブランチ、マージ、リモートとの共有——をカバーします。学習中は手元に置いておきましょう。

更新日:

コマンド機能
git initCreate a new, empty Git repository in the current directory.
git cloneDownload a remote repository and its full history to your machine.
git statusShow changed, staged and untracked files in the working tree.
git addStage changes (files) to be included in the next commit.
git commitRecord staged changes as a new commit with a message.
git logDisplay the commit history of the repository.
git diffShow unstaged or staged differences between states.
git branchList, create or delete branches in the repository.
git checkout / switchSwitch branches or restore files (switch is the modern command).
git mergeJoin another branch's history into the current branch.
git rebaseReapply commits on top of another base commit, rewriting history.
git pullFetch from a remote and merge the changes into the current branch.
git pushUpload local commits to a remote repository.
git stashTemporarily shelve uncommitted changes to reapply later.
git remoteManage the set of remote repositories you track.

注記

よくある質問

merge と rebase の違いは?
merge は2つの親を持つ新しいコミットで履歴を統合します。rebase はあなたのコミットを別のブランチの上に再生し、線形の履歴を作りますがコミットIDを書き換えます。
コミットを取り消すには?
'git revert <コミット>' を使うと変更を打ち消す新しいコミットを追加します(安全で共有履歴を維持)。'git reset' は履歴を書き換えるため共有ブランチでは使わないでください。
git pull と git fetch の違いは?
fetch はリモートからコミットと参照をダウンロードし、作業ツリーには触れません。pull は fetch してからそれらの変更を現在のブランチにマージまたはリベースします。
git stash はいつ使う?
stash は未コミットの変更を一時的に退避し、ブランチの切り替えやきれいなプルを可能にし、後で 'git stash pop' で戻せます。