Git Cheatsheet
A detailed guide to Git, the most popular version control system. Each section has student-friendly explanations and examples you can try while coding.
What is Git?
Git is a version control system that helps you track changes in your code. It allows collaboration, rollback of mistakes, and branching for experimenting safely.
Configuration
Set up Git with your name and email. These details appear in every commit you make.
git config --global user.name "Your Name"
git config --global user.email "you@example.com"
Create a Repository
Start tracking your project with git init
or copy an existing project with git clone
.
git init
git clone https://github.com/user/repo.git
Staging & Committing
Git has a staging area. Use git add
to stage changes and git commit
to save them to history.
git add file.txt
git commit -m "Added file.txt"
Branching & Merging
Branches let you work on features without affecting the main branch. Merge them back when ready.
git branch feature-x
git checkout feature-x
git merge feature-x
Remote Repositories
Connect to GitHub or other hosts using git remote
. Use push
to upload changes and pull
or fetch
to download.
git remote add origin https://github.com/user/repo.git
git push -u origin main
git pull origin main
Undo Changes
Fix mistakes with commands like checkout
, reset
, or revert
. Use carefully!
git checkout -- file.txt
git reset --hard HEAD~1
git revert commit_id
Viewing History
Explore commit history and changes using git log
, git diff
, and git show
.
git log --oneline --graph
git diff
git show commit_id
Stashing
Stash saves changes temporarily so you can switch branches without committing unfinished work.
git stash
git stash pop
Tags
Tags mark important commits (like releases). Use lightweight or annotated tags.
git tag v1.0
git tag -a v1.0 -m "Release v1.0"
git push origin v1.0
Rebasing
Rebase rewrites history by applying commits on top of another branch. Great for a clean commit history, but use with caution in shared branches.
git checkout feature-x
git rebase main
Cherry-pick
Cherry-pick lets you apply a specific commit from one branch to another without merging everything.
git cherry-pick commit_id
Collaboration Workflow
In teams, a common workflow is: fork a repo, clone it, create a branch, push changes, and open a Pull Request.
# Fork on GitHub, then:
git clone https://github.com/your-username/repo.git
git checkout -b new-feature
git push origin new-feature
# Then open a Pull Request on GitHub
How to use this page
- Start with init, clone, add, and commit.
- Learn branching, merging, and pushing to remotes.
- Explore advanced commands like stash, rebase, and cherry-pick.
- Practice workflows by contributing to GitHub projects.
🚀 Explore More Free Developer Tools
Don’t stop here! Supercharge your workflow with our other powerful converters & formatters.
📚 Next.js Cheatsheet
Next.js Cheatsheet
📚 MongoDB Cheatsheet
MongoDB Cheatsheet
📚 Docker Cheatsheet
Docker Cheatsheet
💡 New tools are added regularly — bookmark DevUtilsX and stay ahead!
Want to support my work?
Buy me a coffee