DEV Community

Cover image for ๐Ÿง  Master Git: A Practical Cheatsheet for Developers
Jitendra Rawat
Jitendra Rawat

Posted on • Edited on

๐Ÿง  Master Git: A Practical Cheatsheet for Developers

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
Enter fullscreen mode Exit fullscreen mode

Begin tracking a project in your current directory. This sets up a hidden .git folder.

๐Ÿ“… Clone an Existing Repo

git clone <repo-url>
Enter fullscreen mode Exit fullscreen mode

Download a copy of a remote repository to your local machine.

๐Ÿ“ Tracking and Saving Changes

โž• Stage Files

git add <file>
git add .
Enter fullscreen mode Exit fullscreen mode

Mark files to be included in the next commit.

โœ… Commit Changes

git commit -m "your message"
Enter fullscreen mode Exit fullscreen mode

Save a snapshot of staged changes with a message.

๐Ÿ” View Status

git status
Enter fullscreen mode Exit fullscreen mode

Check whatโ€™s staged, modified, or untracked.

๐Ÿ“Š View Differences

git diff        # unstaged vs working directory  
git diff --cached  # staged vs last commit
Enter fullscreen mode Exit fullscreen mode

๐ŸŒฟ Branching & Merging

๐ŸŒฑ Create a Branch

git branch <branch-name>
Enter fullscreen mode Exit fullscreen mode

๐Ÿ“ Switch Branches

git checkout <branch-name>
git checkout -b <new-branch>
Enter fullscreen mode Exit fullscreen mode

๐Ÿ”€ Merge Branches

git merge <branch-name>
Enter fullscreen mode Exit fullscreen mode

โ˜๏ธ Working with Remotes

๐Ÿ“„ Push Changes

git push origin <branch>
Enter fullscreen mode Exit fullscreen mode

๐Ÿ“… Pull Updates

git pull origin <branch>
Enter fullscreen mode Exit fullscreen mode

๐Ÿ“œ View History

git log
Enter fullscreen mode Exit fullscreen mode

๐Ÿ’  Advanced Commands

โช Revert a Commit

git revert <commit-hash>
Enter fullscreen mode Exit fullscreen mode

Safely undo a commit without rewriting history.

๐Ÿ”€ Reset Commits

git reset --soft HEAD~1  
git reset --mixed HEAD~1  
git reset --hard HEAD~1
Enter fullscreen mode Exit fullscreen mode

Control whether to keep, unstage, or discard changes when going back.

๐Ÿ“ฆ Stash Your Work

git stash
git stash apply
Enter fullscreen mode Exit fullscreen mode

Temporarily save your changes and come back to them later.

๐Ÿ’ Cherry Pick Commits

git cherry-pick <commit-hash>
Enter fullscreen mode Exit fullscreen mode

Apply a specific commit from one branch onto another.

๐Ÿ’ช Rebase Branches

git rebase <branch>
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

๐Ÿ“š Popular Git Workflows

  • Centralized Workflow: Direct commits to main
  • Feature Branch Workflow: Isolated branches per feature
  • Gitflow: Structured with main, develop, release, and feature branches

๐Ÿ”— Connect with me:

๐Ÿ’ผ LinkedIn

๐Ÿ’ป GitHub

Top comments (0)