Git コマンド
毎日使う Git コマンドの実用的なリファレンス - ブランチ操作、取り消し、マージと rebase、そしてリモートとの同期。各コマンドには構文、重要なフラグ、そしてターミナルプレイグラウンドでライブ実行できるコピペ用のサンプルがあります。
セットアップと設定
リポジトリを作成し Git を設定します - init、config、remotes。
git initCreate a new Git repository in the current folder.git remoteList, add, rename, and change the remote repositories your repo points at.git submoduleEmbed one repository inside another and keep it pinned to a specific commit.git cloneCopy a remote repository, with all its history, to your machine.git clone branchClone only a specific branch of a repository, or a single branch only.git configSet your name, email, editor, and other Git settings - globally or per repo.
ステージングとコミット
変更を履歴に記録します - add、commit、amend。
ブランチ操作
ブランチを作成・切り替え・名前変更・削除して、変更を隔離した状態で作業します。
git delete local branchDelete a local branch once its work is merged - and force-delete when it is not.git rename branchRename the branch you are on, or any other branch, locally and on the remote.git create branchCreate a new branch and switch to it, from the current commit or any starting point.git checkoutSwitch branches, restore files, or check out a specific commit.git checkout remote branchFetch and check out a branch that exists on the remote but not yet locally.git branchList, create, rename, and delete branches - the core branch command.git worktreeCheck out multiple branches at once in separate working directories.
変更の取り消し
ミスから復旧する - reset、revert、コミットを安全に取り消します。
git undo commitUndo any commit - an older one, several at once, or one that is already pushed.git resetMove HEAD and choose what happens to the index and working tree: --soft, --mixed, --hard.git revertUndo a commit safely by adding a new commit that reverses it - the right choice for pushed history.git undo last commitUndo just the most recent commit - keep the work, discard it, or reverse it if it was pushed.git reset --hardForce your branch and working tree back to a commit, discarding all changes since it.git stashShelve your uncommitted changes so you can switch context, then reapply them later.git reflogSee everywhere HEAD has been - and recover commits you thought were lost.
マージとリベース
merge、rebase、squash、cherry-pick を使って 2 つのブランチの作業を統合します。
git rebase vs mergeTwo ways to combine branches: a merge commit that preserves history, or a linear replay.git squash commitsCombine several commits into one with interactive rebase for a clean history.git abort mergeCancel a merge in progress and return the branch to the state before you started.git cherry-pickApply a specific commit from one branch onto another, without merging the whole branch.git mergeCombine another branch into your current one, with or without a merge commit.git rebaseReplay your commits on top of another branch for a clean, linear history.
リモート
GitHub などのリモートとローカルリポジトリを同期します - push、pull、fetch。
git fetch vs pullThe difference between downloading remote changes and downloading-and-merging them.git force pushOverwrite the remote branch with your local history - and do it safely with --force-with-lease.git pullDownload remote changes and merge them into your current branch in one step.git pushUpload your commits to a remote and set the upstream branch.git delete remote branchDelete a branch on the remote (GitHub) once it is merged - and locally too.git set upstreamLink a local branch to a remote branch so push and pull need no arguments.git pull remote branchPull changes from a specific remote branch into your current branch.
確認とクリーンアップ
何が変わったかを確認し、作業ツリーをクリーンアップします - status、log、diff、clean。
git remove untracked filesClean untracked files and directories out of the working tree with git clean.git tagMark a commit with a version tag, and push tags to the remote.git statusSee which files are staged, modified, or untracked in your working tree.git diffSee exactly what changed - unstaged, staged, between commits or branches.git bisectBinary-search your history to find the commit that introduced a bug.git logBrowse commit history, with a compact one-line and graph view.