Last Updated: November 21, 2025
Setup & Configuration
git config --global user.name "Your Name"
Set your name for commits
git config --global user.email "email@example.com"
Set your email for commits
git init
Initialize a new Git repository
git clone <url>
Clone a repository from remote
Basic Commands
git status
Check status of working directory
git add <file>
Stage specific file for commit
git add .
Stage all changes for commit
git commit -m "message"
Commit staged changes with message
git commit -am "message"
Stage and commit all tracked files
git log
View commit history
git log --oneline
View compact commit history
Branching & Merging
git branch
List all local branches
git branch <branch-name>
Create new branch
git checkout <branch-name>
Switch to branch
git checkout -b <branch-name>
Create and switch to new branch
git merge <branch-name>
Merge branch into current branch
git branch -d <branch-name>
Delete local branch
Remote Repositories
git remote -v
List remote repositories
git remote add origin <url>
Add remote repository
git push origin <branch>
Push branch to remote
git pull
Fetch and merge from remote
git fetch
Download objects from remote
Undo Changes
git reset <file>
Unstage file
git reset --hard HEAD
Discard all local changes
git revert <commit>
Create new commit that undoes changes
git checkout -- <file>
Discard changes in file
Stashing
git stash
Save changes temporarily
git stash list
List all stashes
git stash pop
Apply and remove most recent stash
git stash apply
Apply most recent stash
💡 Pro Tip:
Use
git commit -m "feat: add feature"
format for conventional commits. Common prefixes: feat, fix, docs, style, refactor, test, chore.