<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: SUGATA CHAKMA</title>
    <description>The latest articles on DEV Community by SUGATA CHAKMA (@sugatadev).</description>
    <link>https://dev.to/sugatadev</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4033526%2F4d05b791-9023-4f96-b14e-c30f1ff3a83d.png</url>
      <title>DEV Community: SUGATA CHAKMA</title>
      <link>https://dev.to/sugatadev</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/sugatadev"/>
    <language>en</language>
    <item>
      <title>🚀 Git Cheat Sheet Every Developer Should Bookmark (Learn Git Faster)</title>
      <dc:creator>SUGATA CHAKMA</dc:creator>
      <pubDate>Fri, 17 Jul 2026 19:00:00 +0000</pubDate>
      <link>https://dev.to/sugatadev/git-cheat-sheet-every-developer-should-bookmark-learn-git-faster-465i</link>
      <guid>https://dev.to/sugatadev/git-cheat-sheet-every-developer-should-bookmark-learn-git-faster-465i</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;"Git isn't hard. Remembering the commands is."&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;If you've ever found yourself Googling:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;em&gt;How do I create a new branch?&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;What's the difference between *&lt;/em&gt;&lt;code&gt;git fetch&lt;/code&gt;** and &lt;strong&gt;&lt;code&gt;git pull&lt;/code&gt;&lt;/strong&gt;?*&lt;/li&gt;
&lt;li&gt;&lt;em&gt;How do I undo my last commit without breaking everything?&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;&lt;em&gt;How do I get back a file I accidentally deleted?&lt;/em&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You're definitely not alone.&lt;/p&gt;

&lt;p&gt;I used to jump between Stack Overflow, documentation, and terminal tabs every time I needed Git. After a while, I realized something important:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;You don't need to memorize Git—you need a practical workflow and a few commands you use every day.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;So in this post, I'm sharing a clean Git cheat sheet with the most useful commands for real-world development. Whether you're working on a side project, collaborating with a team, or shipping features to production, this will help you move faster and with more confidence.&lt;/p&gt;




&lt;h1&gt;
  
  
  Why Git Matters
&lt;/h1&gt;

&lt;p&gt;Git is a &lt;strong&gt;distributed version control system&lt;/strong&gt; that helps developers:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Track code changes&lt;/li&gt;
&lt;li&gt;Collaborate with teammates&lt;/li&gt;
&lt;li&gt;Restore previous versions&lt;/li&gt;
&lt;li&gt;Experiment safely on branches&lt;/li&gt;
&lt;li&gt;Recover from mistakes&lt;/li&gt;
&lt;li&gt;Ship code with confidence&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Whether you're a student, freelancer, or software engineer, Git is one of the most important tools in your workflow.&lt;/p&gt;




&lt;h1&gt;
  
  
  1. Setting Up Git (One-Time Setup)
&lt;/h1&gt;

&lt;p&gt;Before creating repositories, configure your identity.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git config &lt;span class="nt"&gt;--global&lt;/span&gt; user.name &lt;span class="s2"&gt;"Your GitHub UserName"&lt;/span&gt;
git config &lt;span class="nt"&gt;--global&lt;/span&gt; user.email &lt;span class="s2"&gt;"your@email.com"&lt;/span&gt;
git config &lt;span class="nt"&gt;--global&lt;/span&gt; color.ui auto
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This tells Git who is making each commit and enables colorful terminal output for better readability.&lt;/p&gt;

&lt;p&gt;You can also check your current configuration anytime:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git config &lt;span class="nt"&gt;--list&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you want to see only one setting:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git config user.name
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h1&gt;
  
  
  2. Starting a Repository
&lt;/h1&gt;

&lt;p&gt;There are two common ways to begin.&lt;/p&gt;

&lt;h3&gt;
  
  
  Initialize a new project
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git init
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Clone an existing repository
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git clone &amp;lt;repository-url&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Use &lt;code&gt;git init&lt;/code&gt; when starting from scratch.&lt;/p&gt;

&lt;p&gt;Use &lt;code&gt;git clone&lt;/code&gt; when contributing to an existing project.&lt;/p&gt;

&lt;p&gt;If you want to see the remote URL of a cloned repo:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git remote &lt;span class="nt"&gt;-v&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h1&gt;
  
  
  3. The Daily Git Workflow
&lt;/h1&gt;

&lt;p&gt;This is the cycle you'll repeat every day.&lt;/p&gt;

&lt;h2&gt;
  
  
  Check what's changed
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git status
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is usually the first command I run before doing anything else.&lt;/p&gt;




&lt;h2&gt;
  
  
  Stage your changes
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git add filename
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;or stage everything:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git add &lt;span class="nb"&gt;.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you want to stage only parts of a file interactively:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git add &lt;span class="nt"&gt;-p&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That one is especially useful when you want to split a big file into smaller, cleaner commits.&lt;/p&gt;




&lt;h2&gt;
  
  
  Review your changes
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git diff
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;See staged changes:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git diff &lt;span class="nt"&gt;--staged&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you want a compact history view while reviewing work:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git log &lt;span class="nt"&gt;--oneline&lt;/span&gt; &lt;span class="nt"&gt;--graph&lt;/span&gt; &lt;span class="nt"&gt;--decorate&lt;/span&gt; &lt;span class="nt"&gt;--all&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Save your work
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git commit &lt;span class="nt"&gt;-m&lt;/span&gt; &lt;span class="s2"&gt;"Add login validation"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Think of a commit as taking a snapshot of your project.&lt;/p&gt;

&lt;p&gt;A few helpful commit tips:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Keep messages short and clear&lt;/li&gt;
&lt;li&gt;Use present tense&lt;/li&gt;
&lt;li&gt;Make one commit per logical change&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git commit &lt;span class="nt"&gt;-m&lt;/span&gt; &lt;span class="s2"&gt;"Fix navbar alignment on mobile"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you forgot to add a file after committing, you can amend the last commit:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git commit &lt;span class="nt"&gt;--amend&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h1&gt;
  
  
  4. Working with Branches
&lt;/h1&gt;

&lt;p&gt;Branches let you experiment without touching the main project.&lt;/p&gt;

&lt;p&gt;Create a branch:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git branch feature/login
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Switch branches:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git checkout feature/login
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A more modern way to switch branches:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git switch feature/login
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Create and switch in one step:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git switch &lt;span class="nt"&gt;-c&lt;/span&gt; feature/login
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;View branches:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git branch
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;View all branches, including remote ones:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git branch &lt;span class="nt"&gt;-a&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Rename a branch:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git branch &lt;span class="nt"&gt;-m&lt;/span&gt; new-branch-name
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Delete a branch after merging:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git branch &lt;span class="nt"&gt;-d&lt;/span&gt; feature/login
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Merge your work:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git merge feature/login
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This keeps new features isolated until they're ready.&lt;/p&gt;

&lt;p&gt;If you want to bring in just one commit from another branch, use:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git cherry-pick &amp;lt;commit-sha&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That command is incredibly useful when you need a specific fix without merging an entire branch.&lt;/p&gt;




&lt;h1&gt;
  
  
  5. Syncing with GitHub
&lt;/h1&gt;

&lt;p&gt;After committing locally, you'll eventually want to push your code online.&lt;/p&gt;

&lt;p&gt;Add a remote:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git remote add origin &amp;lt;GitHub-repo-url&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Upload commits:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git push origin main
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If this is your first push on a new branch:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git push &lt;span class="nt"&gt;-u&lt;/span&gt; origin feature/login/main/branch
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Download updates and merge them:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git pull
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Fetch without merging:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git fetch origin
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A simple way to remember:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Fetch = Download&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Pull = Download + Merge&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Push = Upload&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you want to inspect the remote branches after fetching:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git branch &lt;span class="nt"&gt;-r&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h1&gt;
  
  
  6. Inspecting History
&lt;/h1&gt;

&lt;p&gt;Need to know who changed what?&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git log
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A cleaner log view:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git log &lt;span class="nt"&gt;--oneline&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Follow changes to a file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git log &lt;span class="nt"&gt;--follow&lt;/span&gt; filename
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Inspect a commit:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git show SHA
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Compare branches:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git diff branchA...branchB
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;See which files changed in a commit:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git show &lt;span class="nt"&gt;--stat&lt;/span&gt; SHA
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;These commands are lifesavers when debugging or reviewing code.&lt;/p&gt;




&lt;h1&gt;
  
  
  7. Save Work for Later with Stash
&lt;/h1&gt;

&lt;p&gt;Imagine you're halfway through a feature when your manager says:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"Can you quickly fix this production bug?"&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Instead of committing unfinished work:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git stash
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can also save with a message:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git stash push &lt;span class="nt"&gt;-m&lt;/span&gt; &lt;span class="s2"&gt;"WIP: login form"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Return later:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git stash pop
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Apply stash without removing it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git stash apply
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;View saved work:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git stash list
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Inspect a stash:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git stash show &lt;span class="nt"&gt;-p&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Delete a stash:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git stash drop
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Clear all stashes:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git stash clear
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Think of &lt;strong&gt;stash&lt;/strong&gt; as Git's temporary locker.&lt;/p&gt;




&lt;h1&gt;
  
  
  8. Moving, Restoring, or Deleting Files
&lt;/h1&gt;

&lt;p&gt;Rename a file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git &lt;span class="nb"&gt;mv &lt;/span&gt;old.js new.js
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Delete a file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git &lt;span class="nb"&gt;rm &lt;/span&gt;file.js
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you want to restore a file you changed:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git restore filename
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Restore a file from staging:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git restore &lt;span class="nt"&gt;--staged&lt;/span&gt; filename
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;These commands are especially helpful when you accidentally edit or remove something you didn't mean to touch.&lt;/p&gt;




&lt;h1&gt;
  
  
  9. Undoing Changes Safely
&lt;/h1&gt;

&lt;p&gt;Sometimes you need to fix mistakes.&lt;/p&gt;

&lt;p&gt;Undo the last commit but keep your changes staged:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git reset &lt;span class="nt"&gt;--soft&lt;/span&gt; HEAD~1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Undo the last commit and keep changes in your working directory:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git reset &lt;span class="nt"&gt;--mixed&lt;/span&gt; HEAD~1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Completely remove the last commit and changes:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git reset &lt;span class="nt"&gt;--hard&lt;/span&gt; HEAD~1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;⚠️ Be careful with &lt;code&gt;--hard&lt;/code&gt;. It can permanently remove uncommitted work.&lt;/p&gt;

&lt;p&gt;If you want to undo a commit safely on a shared branch, use:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git revert &amp;lt;commit-sha&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Unlike &lt;code&gt;reset&lt;/code&gt;, &lt;code&gt;revert&lt;/code&gt; creates a new commit that reverses the changes. This is usually the safer option for team projects.&lt;/p&gt;




&lt;h1&gt;
  
  
  10. Rewriting History (Use Carefully)
&lt;/h1&gt;

&lt;p&gt;Sometimes you need to clean up your branch before merging.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git rebase main
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Interactive rebase is great for cleaning up commits:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git rebase &lt;span class="nt"&gt;-i&lt;/span&gt; HEAD~3
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This lets you squash, reorder, or edit recent commits.&lt;/p&gt;

&lt;p&gt;⚠️ These commands are powerful. Avoid using them on shared branches unless you fully understand the consequences.&lt;/p&gt;

&lt;p&gt;If something goes wrong, Git often keeps a record of where you were:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git reflog
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This command can save you when you think you've lost work.&lt;/p&gt;




&lt;h1&gt;
  
  
  11. Ignore Files You Don't Want to Commit
&lt;/h1&gt;

&lt;p&gt;Create a &lt;code&gt;.gitignore&lt;/code&gt; file.&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;node_modules/
.env
logs/
*.log
dist/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Git will ignore matching files, keeping your repository clean.&lt;/p&gt;

&lt;p&gt;You can also ignore files globally on your machine if needed, but for most projects, a local &lt;code&gt;.gitignore&lt;/code&gt; is enough.&lt;/p&gt;




&lt;h1&gt;
  
  
  12. Cleaning Up Untracked Files
&lt;/h1&gt;

&lt;p&gt;Sometimes your project gets cluttered with generated or temporary files.&lt;/p&gt;

&lt;p&gt;Preview what would be removed:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git clean &lt;span class="nt"&gt;-n&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Remove untracked files:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git clean &lt;span class="nt"&gt;-f&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Remove untracked files and directories:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git clean &lt;span class="nt"&gt;-fd&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;⚠️ Use this carefully. Once deleted, those files are gone unless they were tracked or stashed.&lt;/p&gt;




&lt;h1&gt;
  
  
  13. Tags and Releases
&lt;/h1&gt;

&lt;p&gt;When you're ready to mark a release, tags are very useful.&lt;/p&gt;

&lt;p&gt;Create a tag:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git tag v1.0.0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Create an annotated tag:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git tag &lt;span class="nt"&gt;-a&lt;/span&gt; v1.0.0 &lt;span class="nt"&gt;-m&lt;/span&gt; &lt;span class="s2"&gt;"First stable release"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;List tags:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git tag
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Push tags to GitHub:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git push origin v1.0.0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Or push all tags:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git push origin &lt;span class="nt"&gt;--tags&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Tags are perfect for versioning releases and deployments.&lt;/p&gt;




&lt;h1&gt;
  
  
  My Favorite Git Workflow
&lt;/h1&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Edit Code
      ↓
git status
      ↓
git add .
      ↓
git commit -m "Meaningful message"
      ↓
git pull
      ↓
Resolve conflicts (if any)
      ↓
git push origin main
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Simple.&lt;/p&gt;

&lt;p&gt;Repeat.&lt;/p&gt;

&lt;p&gt;Ship.&lt;/p&gt;




&lt;h1&gt;
  
  
  Bonus: A Few Commands I Use All the Time
&lt;/h1&gt;

&lt;p&gt;Here are some extra Git commands that are worth remembering:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git remote &lt;span class="nt"&gt;-v&lt;/span&gt;
git branch &lt;span class="nt"&gt;-a&lt;/span&gt;
git switch &lt;span class="nt"&gt;-c&lt;/span&gt; feature/new-ui
git add &lt;span class="nt"&gt;-p&lt;/span&gt;
git commit &lt;span class="nt"&gt;--amend&lt;/span&gt;
git revert &amp;lt;commit-sha&amp;gt;
git reflog
git stash push &lt;span class="nt"&gt;-m&lt;/span&gt; &lt;span class="s2"&gt;"WIP"&lt;/span&gt;
git clean &lt;span class="nt"&gt;-fd&lt;/span&gt;
git tag v1.0.0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you learn just these, you'll already be ahead of many developers who only know the basics.&lt;/p&gt;




&lt;h1&gt;
  
  
  Final Thoughts
&lt;/h1&gt;

&lt;p&gt;Git can feel overwhelming at first because there are so many commands.&lt;/p&gt;

&lt;p&gt;The good news?&lt;/p&gt;

&lt;p&gt;You only need about &lt;strong&gt;15–20 commands&lt;/strong&gt; to be productive every day.&lt;/p&gt;

&lt;p&gt;Once these become muscle memory, Git transforms from something intimidating into one of the most powerful tools in your development workflow.&lt;/p&gt;

&lt;p&gt;The real secret is not memorizing everything—it’s understanding the workflow:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;check status&lt;/li&gt;
&lt;li&gt;stage changes&lt;/li&gt;
&lt;li&gt;commit often&lt;/li&gt;
&lt;li&gt;branch for features&lt;/li&gt;
&lt;li&gt;pull before pushing&lt;/li&gt;
&lt;li&gt;stash when interrupted&lt;/li&gt;
&lt;li&gt;revert safely when needed&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That’s the rhythm of working with Git.&lt;/p&gt;




&lt;h2&gt;
  
  
  Quick Question 👇
&lt;/h2&gt;

&lt;p&gt;What's the Git command you always forget?&lt;/p&gt;

&lt;p&gt;Mine used to be:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git stash pop
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Drop your answer in the comments—let's build a community cheat sheet together!&lt;/p&gt;




&lt;p&gt;⭐ If this article helped you, consider leaving a ❤️ and sharing it with another developer who's learning Git.&lt;/p&gt;

</description>
      <category>github</category>
      <category>githubactions</category>
    </item>
  </channel>
</rss>
