Cheatsheets
Git
34 entries
Git
Essential Git commands for version control workflows
34 commands
CommandDescriptionExample
git init
Initialize a new Git repository
git init my-projectgit clone <url>
Clone a remote repository
git clone https://github.com/user/repo.gitgit config --global user.name "Name"
Set your name for commits
git config --global user.name "Jane"git config --global user.email "email"
Set your email for commits
git config --global user.email "[email protected]"git branch
List all local branches
git branchgit branch <name>
Create a new branch
git branch feature/logingit checkout <branch>
Switch to a branch
git checkout maingit checkout -b <name>
Create and switch to a new branch
git checkout -b feature/logingit merge <branch>
Merge a branch into current branch
git merge feature/logingit branch -d <name>
Delete a branch
git branch -d feature/logingit rebase <branch>
Rebase current branch onto another
git rebase maingit add <file>
Stage a file for commit
git add index.htmlgit add .
Stage all changes
git add .git status
Show working tree status
git statusgit diff
Show unstaged changes
git diff src/app.tsgit diff --staged
Show staged changes
git diff --stagedgit commit -m "message"
Commit staged changes with a message
git commit -m "fix: resolve null check"git commit --amend
Amend the last commit
git commit --amendgit push
Push commits to remote
git push origin maingit push -u origin <branch>
Push and set upstream branch
git push -u origin feature/logingit pull
Fetch and merge from remote
git pull origin maingit fetch
Download objects from remote without merging
git fetch --allgit remote -v
Show remote URLs
git remote -vgit stash
Stash current changes
git stashgit stash pop
Apply and remove latest stash
git stash popgit stash list
List all stashes
git stash listgit stash drop
Delete latest stash
git stash drop stash@{0}git reset HEAD <file>
Unstage a file
git reset HEAD src/app.tsgit reset --soft HEAD~1
Undo last commit, keep changes staged
git reset --soft HEAD~1git reset --hard HEAD~1
Undo last commit and discard changes
git reset --hard HEAD~1git revert <commit>
Create a new commit that undoes a previous commit
git revert a1b2c3dgit log --oneline
Show compact commit log
git log --oneline -10git log --graph --oneline
Show commit log with branch graph
git log --graph --oneline --allgit blame <file>
Show who changed each line of a file
git blame src/app.ts