DEV Community

Cover image for πŸš€ Git Cheatsheet for Developers β€” From Basics to Advanced
ABU SAID
ABU SAID

Posted on • Edited on

πŸš€ Git Cheatsheet for Developers β€” From Basics to Advanced

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

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

πŸ“¦ Stage Changes

Add specific files:

git add <file>
Enter fullscreen mode Exit fullscreen mode

Add everything:

git add .
Enter fullscreen mode Exit fullscreen mode

πŸ’Ύ Commit Changes

Save staged changes with a message:

git commit -m "Your message here"
Enter fullscreen mode Exit fullscreen mode

Pro tip: write clear, meaningful messages.


πŸ“Š Check Repository Status

git status
Enter fullscreen mode Exit fullscreen mode

Shows modified, staged, and untracked files.


πŸ” View Differences

Working directory vs staged:

git diff
Enter fullscreen mode Exit fullscreen mode

Staged vs last commit:

git diff --cached
Enter fullscreen mode Exit fullscreen mode

🌿 Branching & Merging

Create branch:

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

Switch branch:

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

Create + switch:

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

Merge:

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

πŸš€ Push Changes

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

πŸ“₯ Pull Updates

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

πŸ“œ View Commit History

git log
Enter fullscreen mode Exit fullscreen mode

βš™οΈ Advanced Git Commands

↩️ Revert a Commit (Safe Undo)

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

Creates a new commit that undoes changes.


🧹 Reset Commits (Rewrite History)

Soft (keep staged):

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

Mixed (unstage):

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

Hard (delete everything):

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

⚠️ Use --hard carefully.


πŸ” Rebase Branches

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

Moves your commits on top of another branch β€” keeps history clean.


πŸ“¦ Stash Work Temporarily

Save changes:

git stash
Enter fullscreen mode Exit fullscreen mode

Restore:

git stash apply
Enter fullscreen mode Exit fullscreen mode

πŸ’ Cherry-Pick a Commit

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

Apply one specific commit to another branch.


πŸͺ Git Hooks

Automate actions before/after Git events.

Location:

.git/hooks/
Enter fullscreen mode Exit fullscreen mode

Examples:

  • pre-commit
  • post-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
Enter fullscreen mode Exit fullscreen mode

Now you can type:

git co main
git cm -m "msg"
Enter fullscreen mode Exit fullscreen mode

πŸ”„ 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:

  • main
  • develop
  • feature/*
  • 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)