Git Commands Cheatsheet
Showing 34 of 34 commands
Setup & Config (4)
git config --global user.name "name"Set username
git config --global user.email "email"Set email
git config --listList all configuration
git initInitialize a new repository
Basic (8)
git statusShow working tree status
git add .Add all files to staging
git add <file>Add specific file to staging
git commit -m "message"Commit staged changes
git commit -am "message"Add and commit in one step
git logShow commit history
git log --onelineShow compact commit history
git diffShow unstaged changes
Branching (6)
git branchList all branches
git branch <name>Create new branch
git checkout <branch>Switch to branch
git checkout -b <branch>Create and switch to branch
git branch -d <branch>Delete branch
git merge <branch>Merge branch into current
Remote (7)
git clone <url>Clone remote repository
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
Undo (5)
git reset HEAD <file>Unstage file
git checkout -- <file>Discard changes in file
git reset --soft HEAD~1Undo last commit, keep changes
git reset --hard HEAD~1Undo last commit, discard changes
git revert <commit>Create new commit that undoes changes
Stash (4)
git stashStash current changes
git stash popApply and remove latest stash
git stash listList all stashes
git stash dropDelete latest stash