An animated, customizable Git cheat sheet drawn by git-sim
Git is a version control system that tracks changes in files and directories. A repository is a folder containing the project's history stored in a hidden .git directory. To create a new repository or clone an existing one, use the git init command. Settings applied globally using the --global flag affect all repositories on the machine and are saved in the ~/.gitconfig file.
Committing changes consists of two steps: staging the desired changes with git add and then committing them as a single snapshot with git commit. Deleting, renaming, untracking, and ignoring files, as well as clearing Git-tracked files, can be done using various git commands. Every commit retains its author, date, and changes.
Git allows you to view and manipulate commit history using commands like git log, git diff, and git grep. These commands do not alter any data. A branch is a movable pointer to a specific commit, with HEAD referring to the active branch. Merging combines the work from one branch into another while preserving the commit history.
Rebasing replays a branch's commits on top of another branch, providing a linear commit history. A cherry-pick replays individual commits while keeping the commit history intact. Remotes are named URLs for other repositories containing the same project. Cloning creates a new repository with a named remote (origin). Fetching and pulling download new commits from a remote, while pushing sends commits to a remote.
The stash command temporarily saves changes that haven't been committed, allowing you to switch branches and reapply the changes later. Git can undo most mistakes if the correct command is used to reverse the action. Each card in a Git cheat sheet displays the potential impact of the corresponding command.
Written by urgent.news from Lobsters's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.