Commands
Every command the engine models, with what it does to the repository rather than what its name suggests. The gap between those two is most of why git is hard.
40 commands modelled · 45 explained
git init- Create an empty repository in this directory
git hash-object- Show the object id a file's contents would get, and with -w store it · Objects and hashes
git cat-file- Print an object's type, size or contents exactly as stored · Objects and hashes
git ls-tree- List what a tree records, which is one directory of a commit
git ls-files- List the paths the index is tracking, with -s showing their stages
git add- Copy the current contents of a file into the index · Your first commit
git rm- Remove a file from the index, and unless --cached from disk too
git mv- Move a tracked file, updating the index in the same step
git status- Report the two gaps: HEAD against the index, and the index against your files · The index
git commit- Record the index as a new commit on the current branch · Your first commit
git commit --amend- Replace the last commit with a new one built from the index · Amending
git restore- Copy a file back from the index, or with --staged from HEAD into the index · Unstaging and discarding
git reset- Move the current branch, and depending on the mode the index and files too · Moving the branch
git reset --hard- Move the branch and overwrite the index and your files — the one that loses work · Throwing work away
git log- Walk the history reachable from a commit, newest first
git show- Print one object in full, with its diff when it is a commit
git diff- Compare two of the three trees, or two commits
git branch- List, create or delete the names that point at commits · What a branch is
git switch- Move HEAD to another branch, and with -c create it first · What a branch is
git checkout- Move HEAD, or restore files — the older command that does both jobs · What a branch is
git tag- Give a commit a name that will not move · Tags
git merge- Join another branch's history into this one · Fast-forward and true merges
git merge --abort- Undo a conflicted merge, restoring the state you started from · Conflicts
git merge-base- Find the commit two branches diverged from · Fast-forward and true merges
git rebase- Replay this branch's commits onto a different base, as new commits · Rebasing
git rebase --continue- Carry on with a rebase after resolving and staging a conflict · Finish an abandoned rebase
git rebase --abort- Stop a rebase and put the branch back where it started · Finish an abandoned rebase
git cherry-pick- Apply the change one commit made, here, as a new commit · Cherry-pick and revert
git revert- Record a new commit that undoes an earlier one · Cherry-pick and revert
git stash- Set aside uncommitted work as real commits, and restore your last commit
git reflog- Show every position a ref has held, and what moved it there · Undo a hard reset
git remote- List or configure the repositories this one can exchange objects with · Tracking branches
git clone- Copy another repository and remember where it came from
git fetch- Update your record of a remote without touching your branches · Tracking branches
git pull- Fetch, then merge or rebase the result into the current branch
git push- Send commits to a remote, if doing so would not remove any · Tracking branches
git push --force- Send commits even if that removes some from the remote · Force-pushing
git push --force-with-lease- Force, but only while the remote is where you last saw it · Force-pushing
git bisect- Binary-search history for the commit that introduced a change · Bisect
git blame- Show which commit last touched each line of a file
git fsck- Check the object store, and report objects nothing points at · Rescue a deleted branch
git gc- Delete unreachable objects — after this, they are genuinely gone · When it is genuinely too late
git filter-branch- Rewrite every commit, for example to remove a file from all of history · Purge a committed secret
git config- Read and write repository settings
git rev-parse- Resolve a revision expression to the object id it names