Introduction to Git
Git is the most popular version control system used by developers to track code changes, collaborate efficiently, and manage project history with confidence. Whether you're working solo or as part of a large engineering team, Git has become an essential tool in modern software development.
However, mastering Git can feel overwhelming at first β especially with its wide range of commands and workflows.
Thatβs why this Git Cheatsheet breaks down both essential and advanced Git commands in a clear, practical way. From creating repositories to branching strategies, stashing work, and rewriting history β this guide will help you work faster, cleaner, and smarter with Git.
Perfect for:
β
Beginners learning Git
β
Developers refreshing their skills
β
Pros optimizing daily workflow
π Basic Git Commands
π§ Initialize a Repository
Create a new Git repo in your current folder:
git init
This adds a hidden .git folder that tracks your project history.
π₯ Clone a Repository
Copy an existing repo to your local machine:
git clone <repository-url>
π¦ Stage Changes
Add specific files:
git add <file>
Add everything:
git add .
πΎ Commit Changes
Save staged changes with a message:
git commit -m "Your message here"
Pro tip: write clear, meaningful messages.
π Check Repository Status
git status
Shows modified, staged, and untracked files.
π View Differences
Working directory vs staged:
git diff
Staged vs last commit:
git diff --cached
πΏ Branching & Merging
Create branch:
git branch <branch-name>
Switch branch:
git checkout <branch-name>
Create + switch:
git checkout -b <branch-name>
Merge:
git merge <branch-name>
π Push Changes
git push <remote> <branch>
π₯ Pull Updates
git pull <remote> <branch>
π View Commit History
git log
βοΈ Advanced Git Commands
β©οΈ Revert a Commit (Safe Undo)
git revert <commit-hash>
Creates a new commit that undoes changes.
π§Ή Reset Commits (Rewrite History)
Soft (keep staged):
git reset --soft HEAD~1
Mixed (unstage):
git reset --mixed HEAD~1
Hard (delete everything):
git reset --hard HEAD~1
β οΈ Use --hard carefully.
π Rebase Branches
git rebase <branch-name>
Moves your commits on top of another branch β keeps history clean.
π¦ Stash Work Temporarily
Save changes:
git stash
Restore:
git stash apply
π Cherry-Pick a Commit
git cherry-pick <commit-hash>
Apply one specific commit to another branch.
πͺ Git Hooks
Automate actions before/after Git events.
Location:
.git/hooks/
Examples:
pre-commitpost-merge
Use them for formatting, tests, or validations.
β‘ Git Aliases (Speed Mode)
Create shortcuts:
git config --global alias.co checkout
git config --global alias.cm commit
git config --global alias.br branch
Now you can type:
git co main
git cm -m "msg"
π Popular Git Workflows
β Centralized Workflow
Single main branch β simple but limited.
π± Feature Branch Workflow
Each feature gets its own branch (most common).
π¦ Gitflow Workflow
Structured branches:
maindevelopfeature/*release/*
Great for large teams and releases.
π― Final Thoughts
Git isnβt just a tool β itβs a core developer skill.
Once you master:
β Version control
β Branching strategies
β Clean history
β Collaboration
Your productivity skyrockets.
Use this cheatsheet as a quick reference β and over time, Git will feel natural instead of confusing.
π Letβs Connect
πΌ LinkedIn: https://www.linkedin.com/in/abu-said-bd/
π» GitHub: https://github.com/said7388
Top comments (0)