Setup & ConfigSet global git username
git config --global user.name "Your Name"Setup & ConfigSet global git email
git config --global user.email "you@example.com"Setup & ConfigSet default branch name to main
git config --global init.defaultBranch mainSetup & ConfigList all configuration variables with file location
git config --list --show-originGetting StartedInitialize a new local Git repository
git initGetting StartedClone a remote repository to local machine
git clone <repo-url>Getting StartedShallow clone only latest commit to save bandwidth
git clone --depth 1 <repo-url>Basic SnapshottingShow repository status in short branch format
git status -sbBasic SnapshottingStage all modified and untracked files
git add .Basic SnapshottingInteractively stage hunks / parts of modified files
git add -pBasic SnapshottingCommit staged changes with message
git commit -m "feat: commit message"Basic SnapshottingAdd staged files to the previous commit without changing message
git commit --amend --no-editBasic SnapshottingShow unstaged changes in working tree
git diffBasic SnapshottingShow staged changes ready to be committed
git diff --stagedBranchingList all local and remote tracking branches
git branch -aBranchingCreate and switch to a new branch
git switch -c <branch-name>BranchingSwitch to an existing branch
git switch <branch-name>BranchingDelete a local branch that has been merged
git branch -d <branch-name>BranchingForce delete a local branch regardless of merge status
git branch -D <branch-name>BranchingMerge specified branch into current active branch
git merge <branch-name>BranchingAbort a conflicting merge and reset to pre-merge state
git merge --abortRemote SyncList all configured remote repositories
git remote -vRemote SyncFetch all branches from remote and remove deleted remote tracking branches
git fetch --all --pruneRemote SyncFetch and replay local commits on top of remote branch
git pull --rebase origin <branch>Remote SyncPush current branch and set upstream tracking
git push -u origin <branch>Remote SyncDelete a remote branch on the server
git push origin --delete <branch>Undo & RevertDiscard unstaged changes in working directory for a file
git restore <file>Undo & RevertUnstage a file while keeping its changes in working directory
git restore --staged <file>Undo & RevertUndo last commit, keeping changes staged
git reset --soft HEAD~1Undo & RevertUndo last commit, keeping changes unstaged in working directory
git reset --mixed HEAD~1Undo & RevertDiscard last commit and all its working tree changes completely
git reset --hard HEAD~1Undo & RevertCreate a new commit that safely reverses a specific commit
git revert <commit-hash>Stash & HistoryStash tracked and untracked changes with description
git stash push -u -m 'wip'Stash & HistoryList all stashed changes
git stash listStash & HistoryApply and remove latest stashed state
git stash popStash & HistoryView formatted visual commit history tree
git log --oneline --graph --allStash & HistoryApply an existing commit from another branch to current branch
git cherry-pick <commit-hash>Stash & HistoryRemove untracked files and directories forcefully
git clean -fd