Setup & Configuration
git config --global user.name "Your Name" – Set your usernamegit config --global user.email "your@email.com" – Set your emailgit config --list – View all configuration settingsCreating & Cloning Repositories
git init – Initialize a new Git repositorygit clone <url> – Clone a remote repositoryBasic Workflow
git status – Check status of working directorygit add <file> – Stage specific filegit add . – Stage all changesgit commit -m "message" – Commit staged changesgit commit -am "message" – Stage and commit tracked filesBranching & Merging
git branch – List all branchesgit branch <name> – Create new branchgit checkout <branch> – Switch to branchgit checkout -b <branch> – Create and switch to new branchgit switch <branch> – Switch to branch (newer syntax)git merge <branch> – Merge branch into current branchgit branch -d <branch> – Delete branchRemote Repositories
git remote -v – List remote repositoriesgit fetch – Download changes from remotegit pull – Fetch and merge changes from remotegit push – Upload local commits to remotegit push origin <branch> – Push branch to remotegit push -u origin <branch> – Push and set upstream branchViewing History
git log – View commit historygit log --oneline – Compact commit historygit log --graph --oneline --all – Visual branch historygit diff – Show unstaged changesgit diff --staged – Show staged changesgit show <commit> – Show specific commit detailsUndoing Changes
git restore <file> – Discard changes in working directorygit restore --staged <file> – Unstage filegit reset HEAD~1 – Undo last commit (keep changes)git reset --hard HEAD~1 – Undo last commit (discard changes)git revert <commit> – Create new commit that undoes changesStashing
git stash – Save changes temporarilygit stash pop – Apply and remove most recent stashgit stash list – List all stashesgit stash apply – Apply stash without removing itOther Useful Commands
git rm <file> – Remove file and stage deletiongit mv <old> <new> – Rename/move filegit tag <name> – Create taggit cherry-pick <commit> – Apply specific commit to current branchgit rebase <branch> – Reapply commits on top of another branchThese commands cover the vast majority of day-to-day Git operations!