This repository serves as a quick and easy reference for commonly used Git and GitHub commands. The commands are organized into granular files within the cheatsheets/ directory for easier navigation:
01-basics.md: Git setup, configuration, repository initialization, basic workflow, and amending commits.02-history.md: Viewing commit history, inspecting specific commits, and patch views (log/diff).03-stash.md: Saving unfinished work with descriptive stashing and ignoring files (.gitignore).04-branch.md: Branch management and resolving merge conflicts.05-remote.md: Working with remote repositories and remote cleanup/pruning.06-undo.md: The Safety Net (reflog), undoing changes, and interactive rebasing.
Simply click on any of the links above or navigate to the cheatsheets/ directory and open the relevant .md file. Each command is accompanied by a short, descriptive explanation and modern syntax.
Based on common developer workflows, here are the top 15+ commands you'll likely use every day:
| Command | Purpose |
|---|---|
git status |
Check the state of your working directory and staging area. |
git add . |
Stage all current changes for the next commit. |
git commit -m "msg" |
Save your staged changes with a descriptive message. |
git commit --amend |
Fix the last commit (fix message or add forgotten files). |
git pull |
Fetch from and integrate with another repository or local branch. |
git push |
Update remote refs along with associated objects. |
git switch -c <name> |
(Recommended) Create a new branch and switch to it. |
git switch <name> |
(Recommended) Switch to an existing branch. |
git merge <name> |
Join two or more development histories together. |
git log --oneline |
View a condensed version of the project history. |
git show <commit> |
Show changes and metadata for a specific commit. |
git stash push -m "msg" |
Save changes with a message to a temporary storage area. |
git diff --staged |
Show changes between your staging area and last commit. |
git branch -vv |
List branches with their tracking remote and status. |
git fetch --prune |
Download remote changes and clean up stale tracking branches. |
git restore . |
(Recommended) Discard all local changes in current directory. |
git reflog |
View record of all Git actions (The ultimate "undo" tool). |
Feel free to suggest improvements or additional commands by opening an issue or a pull request!