Introduction: Whether you're a solo developer or collaborating with a team, version control is non-negotiableโand Git is the standard. It helps manage code changes, track history, experiment safely, and work across branches. But letโs be honest: Git's power can be overwhelming at first. Thatโs why Iโve compiled this concise, no-fluff Git cheatsheet to help you get up to speed quickly and stay productive.
๐ Getting Started
๐ง Initialize a Repository
git init
Begin tracking a project in your current directory. This sets up a hidden .git folder.
๐
Clone an Existing Repo
git clone <repo-url>
Download a copy of a remote repository to your local machine.
๐ Tracking and Saving Changes
โ Stage Files
git add <file>
git add .
Mark files to be included in the next commit.
โ
Commit Changes
git commit -m "your message"
Save a snapshot of staged changes with a message.
๐ View Status
git status
Check whatโs staged, modified, or untracked.
๐ View Differences
git diff # unstaged vs working directory
git diff --cached # staged vs last commit
๐ฟ Branching & Merging
๐ฑ Create a Branch
git branch <branch-name>
๐ Switch Branches
git checkout <branch-name>
git checkout -b <new-branch>
๐ Merge Branches
git merge <branch-name>
โ๏ธ Working with Remotes
๐ Push Changes
git push origin <branch>
๐
Pull Updates
git pull origin <branch>
๐ View History
git log
๐ Advanced Commands
โช Revert a Commit
git revert <commit-hash>
Safely undo a commit without rewriting history.
๐ Reset Commits
git reset --soft HEAD~1
git reset --mixed HEAD~1
git reset --hard HEAD~1
Control whether to keep, unstage, or discard changes when going back.
๐ฆ Stash Your Work
git stash
git stash apply
Temporarily save your changes and come back to them later.
๐ Cherry Pick Commits
git cherry-pick <commit-hash>
Apply a specific commit from one branch onto another.
๐ช Rebase Branches
git rebase <branch>
Reapply commits from one branch on top of another for a cleaner history.
โ๏ธ Productivity Boosters
โ Git Hooks
Automate tasks before/after Git events by placing scripts in .git/hooks
.
โก Create Aliases
git config --global alias.co checkout
git config --global alias.br branch
๐ Popular Git Workflows
-
Centralized Workflow: Direct commits to
main
- Feature Branch Workflow: Isolated branches per feature
-
Gitflow: Structured with
main
,develop
,release
, andfeature
branches
Top comments (0)