Git Commands Reference Matrix
The definitive Git command cheat sheet: branching, stashing, rebasing, committing, and undoing mistakes with 1-click copy.
Setup & Configuration (3 commands)
git config --global user.name "Your Name"
Sets the name associated with your commit history globally.
git config --global user.email "[email protected]"
Sets the email address attached to your git commits.
git config --global core.defaultBranch main
Sets "main" as the default primary branch for new repositories.
Basic Operations (6 commands)
git init
Initializes a new, empty Git repository in the current directory.
git clone <repo-url>
Clones an entire remote repository onto your local disk.
git status
Displays the state of the working directory and staging area.
git add .
Stages all modified and new files in the repository for the next commit.
git commit -m "feat: descriptive commit message"
Commits staged changes with a concise commit message.
git commit --amend --no-edit
Appends staged changes to the most recent commit without changing message.
Branching & Merging (5 commands)
git branch
Lists all local branches in the repository.
git checkout -b <new-feature-branch>
Creates a new branch and immediately switches to it.
git switch <branch-name>
Switches to an existing branch cleanly.
git merge <feature-branch>
Merges the specified branch into your current active branch.
git branch -d <branch-name>
Deletes a local branch that has already been merged.
Remote Sync (3 commands)
git fetch origin
Downloads commits and branches from the remote repository without merging.
git pull origin main --rebase
Fetches and integrates remote changes on top of your local branch linearly.
git push -u origin <branch-name>
Pushes your local branch to the remote repo and sets upstream tracking.
Stashing Work (3 commands)
git stash
Temporarily shelve uncommitted local changes to work on another branch.
git stash pop
Applies the most recently stashed changes and removes them from stash list.
git stash list
Lists all stashed changesets currently preserved.
History & Inspection (3 commands)
git log --oneline --graph --decorate --all
Displays an ASCII graph of commit history across all branches.
git diff
Shows line-by-line differences of unstaged changes in working tree.
git blame <file>
Annotates each line in a file with the author, commit hash, and timestamp.
Undoing Mistakes (4 commands)
git restore <file>
Discards unstaged modifications in the specified file.
git restore --staged <file>
Unstages a file while keeping its modifications in your working folder.
git reset --soft HEAD~1
Undoes the last commit but keeps all changes staged and intact.
git revert <commit-hash>
Creates a new commit that exactly inverts the changes of a past commit.