Git Commands Cheatsheet: Complete Architecture & Quick Reference
Everyday Git commands for cloning, staging, branching, stash, merge conflicts, and undoing commits.
Setup & Configuration
Sets the author name attached to all your commits.
git config --global user.name "Your Name"Sets the committer email address.
git config --global user.email "email@example.com"Initializes a brand new .git directory in the current folder.
git initClones a remote repository to your local computer.
git clone <url>Staging & Committing
Shows modified, staged, and untracked files.
git statusStages all modifications in the current directory.
git add .Records staged snapshot with a descriptive message.
git commit -m "Commit message"Short-cut to stage modified tracked files and commit in one command.
git commit -am "Message"Adds staged changes to the previous commit without changing the commit message.
git commit --amend --no-editBranching & Merging
Creates a new branch and checks it out immediately.
git switch -c <branch-name>Lists existing local branches with the active branch marked.
git branchMerges the specified branch into your currently checked out branch.
git merge <branch-name>Deletes a branch only if it has already been merged.
git branch -d <branch-name>Stashing & Temporary Storage
Temporarily shelves modified tracked files to give you a clean working tree.
git stashRestores the most recently stashed changes and deletes them from the stash list.
git stash popDisplays all saved stashes in the current repository.
git stash listUndoing Mistakes
Restores file to its state at HEAD, discarding local edits.
git restore <file>Removes a file from the staging area without deleting its contents.
git restore --staged <file>Moves HEAD back 1 commit while leaving your edits staged.
git reset --soft HEAD~1Creates a new inverse commit to cleanly undo changes on shared remote branches.
git revert <commit-hash>Open Diff & Compare Tool
Compare two JSON values and find field-level differences.
FAQ
Frequently Asked Questions
What is the difference between git reset and git revert?
git reset rewrites commit history locally (best for unpushed commits). git revert creates a brand new commit that inverts the changes, making it safe for public shared branches.