3 commands
git config --global user.name "Name"Set global username
git config --global user.email "email"Set global email
git config --listList all config settings
3 commands
git initInitialize a local repository
git clone <url>Clone a remote repository
git clone <url> <dir>Clone into a specific directory
8 commands
git statusShow working tree status
git add <file>Stage a specific file
git add .Stage all changes
git add -pStage changes interactively
git diffShow unstaged changes
git diff --stagedShow staged changes
git restore <file>Discard working directory changes
git restore --staged <file>Unstage a file
6 commands
git commit -m "message"Commit staged changes
git commit -am "message"Stage tracked files and commit
git commit --amendModify the last commit
git logShow commit history
git log --oneline --graphCompact graph log
git show <commit>Show commit details
9 commands
git branchList local branches
git branch -aList all branches (including remote)
git branch <name>Create a new branch
git checkout <branch>Switch to a branch
git checkout -b <branch>Create and switch to new branch
git switch <branch>Switch branch (modern)
git switch -c <branch>Create and switch (modern)
git branch -d <branch>Delete a merged branch
git branch -D <branch>Force delete a branch
5 commands
git merge <branch>Merge branch into current
git merge --no-ff <branch>Merge with a merge commit
git rebase <branch>Rebase onto a branch
git rebase -i HEAD~nInteractive rebase last n commits
git cherry-pick <commit>Apply a specific commit
7 commands
git stashStash working changes
git stash push -m "msg"Stash with a message
git stash listList stashes
git stash popApply and remove latest stash
git stash apply stash@{n}Apply a specific stash
git stash drop stash@{n}Delete a stash
git stash clearRemove all stashes
6 commands
git log --author="name"Filter commits by author
git log --since="2 weeks ago"Commits in last 2 weeks
git blame <file>Show who changed each line
git diff <branch1>..<branch2>Diff between two branches
git tagList all tags
git tag -a v1.0 -m "msg"Create an annotated tag
9 commands
git remote -vList remote connections
git remote add origin <url>Add a remote
git fetch originFetch from remote
git pullFetch and merge from remote
git pull --rebaseFetch and rebase from remote
git push origin <branch>Push branch to remote
git push -u origin <branch>Push and set upstream
git push --force-with-leaseSafe force push
git push origin --delete <branch>Delete remote branch
6 commands
git revert <commit>Revert a commit (safe)
git reset --soft HEAD~1Undo last commit, keep staged
git reset --mixed HEAD~1Undo last commit, keep unstaged
git reset --hard HEAD~1Undo last commit, discard changes
git clean -fdRemove untracked files/dirs
git reflogShow history of HEAD movements