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.gitStaging & 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-xRemote 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 mainUndo Changes
Fix mistakes with commands like checkout, reset, or revert. Use carefully!
git checkout -- file.txt
git reset --hard HEAD~1
git revert commit_idViewing History
Explore commit history and changes using git log, git diff, and git show.
git log --oneline --graph
git diff
git show commit_idStashing
Stash saves changes temporarily so you can switch branches without committing unfinished work.
git stash
git stash popTags
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.0Rebasing
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 mainCherry-pick
Cherry-pick lets you apply a specific commit from one branch to another without merging everything.
git cherry-pick commit_idCollaboration 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 GitHubHow 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