Git Commands
Essential Git commands reference with descriptions.
Setup & Config
git config --global user.name "Your Name"Set your name
git config --global user.email "email@example.com"Set your email
git config --listList all settings
git initInitialize a new repository
git clone <url>Clone a repository
Basic Commands
git statusCheck status of working directory
git add <file>Stage a file
git add .Stage all changes
git commit -m "message"Commit staged changes
git commit -am "message"Stage and commit all changes
git diffShow unstaged changes
git diff --stagedShow staged changes
Branching
git branchList all branches
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 branch -d <branch>Delete a branch
git merge <branch>Merge branch into current branch
Remote
git remote -vList remote repositories
git remote add origin <url>Add remote repository
git push origin <branch>Push to remote branch
git push -u origin <branch>Push and set upstream
git pullFetch and merge from remote
git fetchDownload remote changes
History
git logShow commit history
git log --onelineShow condensed history
git log --graphShow branch graph
git show <commit>Show commit details
git blame <file>Show who changed each line
Undo Changes
git reset <file>Unstage a file
git reset --hardDiscard all changes
git checkout -- <file>Discard changes to file
git revert <commit>Create new commit that undoes changes
git clean -fdRemove untracked files and directories
Stashing
git stashStash current changes
git stash listList all stashes
git stash popApply and remove latest stash
git stash applyApply latest stash
git stash dropDelete latest stash
Tags
git tagList all tags
git tag <name>Create a lightweight tag
git tag -a <name> -m "message"Create annotated tag
git push origin <tag>Push tag to remote
git push origin --tagsPush all tags