Git Cheatsheet

Senior Backend Engineer
Search for a command to run...

Senior Backend Engineer
No comments yet. Be the first to comment.
Install Redis cli $ brew install redis-cli General PING # Test connection, returns PONG AUTH <password> # Authenticate with password SELECT <db> # Switch to a specific database (default is 0) DBSIZE # Get total nu...

InfluxDB 3 client: influxctl influxctl is the official command-line tool for managing and interacting with InfluxDB 3 clusters. Think of it as your Swiss Army knife for database setup, bucket management, and query execution. This cheatsheet gives you...
Here is an extended and fully annotated version of the Linux Cheatsheet blog in Markdown, with: Brief descriptions for each command An Advanced Topics section covering cron, systemd, firewalld, SELinux, and more Linux Cheat sheet System Informat...

1 Year on LeetCode: Lessons, Struggles, and Growth Exactly one year ago, I made a commitment — to open LeetCode daily, without excuses, and start solving problems that once made me uncomfortable. What started as a casual attempt to improve my DSA ski...

Whether you're just getting started with Git or you're a seasoned developer, having a handy cheatsheet saves time and avoids Googling the same commands over and over again. This guide is organized into Basic, Intermediate, and Advanced sections to cover all levels of Git usage.
These commands help you set up a repository and perform everyday version control tasks.
git config --global user.name "Your Name"
git config --global user.email "you@example.com"
git config --global init.defaultBranch main
git init # Initialize a new Git repo
git clone https://github.com/user/repo.git # Clone an existing repo
git status # See changes
git add file.txt # Stage a file
git add . # Stage all changes
git commit -m "message" # Commit staged changes
git branch # List branches
git switch main # Switch to branch 'main'
git switch -c new-feature # Create and switch to 'new-feature'
git merge main # Merge 'main' into current branch
Useful when working in teams and collaborating via remote repositories.
git remote -v # Show remotes
git remote add origin URL # Add remote repo
git push -u origin main # Push first time with upstream
git push # Push commits
git pull # Fetch and merge from origin
git fetch # Fetch changes without merging
git rm file.txt # Remove a tracked file
git mv old.txt new.txt # Rename or move file
git restore file.txt # Discard local changes
git restore --staged file.txt # Unstage a file
git log # Full commit history
git log --oneline --graph # Compact and visual log
git diff # View unstaged changes
git diff --staged # View staged changes
git blame file.txt # Show who last modified each line
Commands for rewriting history, debugging, and working with complex workflows.
git commit --amend # Edit the last commit
git rebase -i HEAD~3 # Interactive rebase last 3 commits
git reflog # Show all history (even deleted commits)
git stash # Temporarily save changes
git stash pop # Reapply saved changes
git reset HEAD~1 # Undo last commit (keep changes)
git reset --hard HEAD~1 # Delete last commit and changes
git clean -fd # Remove untracked files and folders
git merge --abort # Abort a merge
git rebase --abort # Abort a rebase
git cherry-pick <commit> # Apply a specific commit
git bisect start # Start binary search for bugs
git bisect bad # Mark current commit as bad
git bisect good <commit> # Mark known good commit
git bisect reset # End bisect session
Typing full Git commands repeatedly can be tedious. These aliases make common tasks faster and easier. Add them to your ~/.bashrc or ~/.zshrc.
alias gs="git status"
alias ga="git add"
alias gaa="git add ."
alias gc="git commit -m"
alias gcm="git commit -m"
alias gsw="git switch"
alias gswc="git switch -c"
alias gb="git branch"
alias gm="git merge"
alias gp="git push"
alias gpl="git pull"
alias gl="git log --oneline --graph --decorate"
alias gd="git diff"
alias gds="git diff --staged"
alias gr="git restore"
alias grs="git restore --staged"
alias gstash="git stash"
alias gpop="git stash pop"
alias grh="git reset --hard"
alias gundo="git reset --soft HEAD~1"
gs # git status
gaa # git add .
gcm "msg" # git commit -m "msg"
gswc feat-x # git switch -c feat-x
source ~/.bashrc # or ~/.zshrc
Prefer aliases within Git itself? Add these:
git config --global alias.st status
git config --global alias.ci commit
git config --global alias.sw switch
git config --global alias.br branch
git config --global alias.lg "log --oneline --graph --decorate"
Use them like:
git st
git sw main
git lg
This cheatsheet covers the most essential Git commands for day-to-day development and collaboration. As your workflow becomes more advanced, these quick references will help you stay productive and efficient.
Happy coding!