<?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: Marvelbiz Solutions</title>
    <description>The latest articles on DEV Community by Marvelbiz Solutions (@alexmerveille).</description>
    <link>https://dev.to/alexmerveille</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.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3933330%2Fec8c6a61-e66f-499f-917a-1921d1b01db5.jpg</url>
      <title>DEV Community: Marvelbiz Solutions</title>
      <link>https://dev.to/alexmerveille</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/alexmerveille"/>
    <language>en</language>
    <item>
      <title>Git Crash Course: From Absolute Beginner to Confident User</title>
      <dc:creator>Marvelbiz Solutions</dc:creator>
      <pubDate>Fri, 05 Jun 2026 01:49:00 +0000</pubDate>
      <link>https://dev.to/alexmerveille/git-crash-course-from-absolute-beginner-to-confident-user-1gcd</link>
      <guid>https://dev.to/alexmerveille/git-crash-course-from-absolute-beginner-to-confident-user-1gcd</guid>
      <description>&lt;p&gt;&lt;em&gt;A complete, hands-on guide to version control that actually makes sense&lt;/em&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  Before We Begin: Why Git Matters
&lt;/h2&gt;

&lt;p&gt;I'll never forget my first week as a junior developer. I'd been working on a feature for three days when my computer crashed. The file corrupted. Three days of work, gone forever. I literally cried at my desk.&lt;/p&gt;

&lt;p&gt;My senior dev walked over, looked at my screen, and said something I'll never forget: "You didn't use Git?"&lt;/p&gt;

&lt;p&gt;That night, I learned Git. I've never lost work since.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Git is a time machine for your code.&lt;/strong&gt; It lets you:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Travel back to any previous version of your project&lt;/li&gt;
&lt;li&gt;Work on multiple features simultaneously without them interfering&lt;/li&gt;
&lt;li&gt;Collaborate with others without accidentally overwriting their work&lt;/li&gt;
&lt;li&gt;Experiment freely, knowing you can always undo&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This tutorial will take you from "Git? Isn't that a type of fruit?" to confidently using Git in your daily workflow.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What you'll learn:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Core concepts explained simply&lt;/li&gt;
&lt;li&gt;Step-by-step commands with real examples&lt;/li&gt;
&lt;li&gt;Daily workflows you'll actually use&lt;/li&gt;
&lt;li&gt;How to fix mistakes (because you will make them)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Prerequisites:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A computer (Mac, Windows, or Linux)&lt;/li&gt;
&lt;li&gt;Ability to open a terminal/command prompt&lt;/li&gt;
&lt;li&gt;A text editor&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Time to complete:&lt;/strong&gt; About 1-2 hours&lt;/p&gt;

&lt;p&gt;Let's start your Git journey.&lt;/p&gt;




&lt;h2&gt;
  
  
  Part 1: What Is Version Control? (The Mental Model)
&lt;/h2&gt;

&lt;h3&gt;
  
  
  The Problem Git Solves
&lt;/h3&gt;

&lt;p&gt;Imagine you're writing an essay. You might do this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;essay_final.docx
essay_final2.docx
essay_final_really_final.docx
essay_final_OMG_this_time_for_real.docx
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We've all been there. This is &lt;strong&gt;manual version control&lt;/strong&gt;, and it's terrible.&lt;/p&gt;

&lt;p&gt;Git solves this by tracking every change automatically. Think of it as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;A snapshot machine&lt;/strong&gt; — Every time you save, Git takes a picture of your entire project&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;A time machine&lt;/strong&gt; — You can go back to any snapshot&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;A parallel universe generator&lt;/strong&gt; — Create alternate timelines to try ideas safely&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  The Three States of Git
&lt;/h3&gt;

&lt;p&gt;Everything in Git exists in one of three states:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Working Directory → Staging Area → Repository
     (your files)     (ready to save)   (saved forever)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Think of it like preparing a photo album:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Working Directory&lt;/strong&gt; — You take photos (make changes to files)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Staging Area&lt;/strong&gt; — You select which photos to put in the album (choose what to save)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Repository&lt;/strong&gt; — You paste them in the album permanently (commit)&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Let's see this in action.&lt;/p&gt;




&lt;h2&gt;
  
  
  Part 2: Installing and Configuring Git
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Step 1: Install Git
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Mac:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Using Homebrew (recommended)&lt;/span&gt;
brew &lt;span class="nb"&gt;install &lt;/span&gt;git

&lt;span class="c"&gt;# Or download from git-scm.com&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Windows:&lt;/strong&gt;&lt;br&gt;
Download from &lt;a href="https://git-scm.com" rel="noopener noreferrer"&gt;git-scm.com&lt;/a&gt; and run the installer. Choose "Git Bash" during installation—it gives you a Linux-like terminal.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Linux (Ubuntu/Debian):&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;apt update
&lt;span class="nb"&gt;sudo &lt;/span&gt;apt &lt;span class="nb"&gt;install &lt;/span&gt;git
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 2: Verify Installation
&lt;/h3&gt;



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

&lt;/div&gt;



&lt;p&gt;You should see something like &lt;code&gt;git version 2.40.0&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 3: Configure Your Identity
&lt;/h3&gt;

&lt;p&gt;Git needs to know who you are. This information gets attached to every save:&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 Name"&lt;/span&gt;
git config &lt;span class="nt"&gt;--global&lt;/span&gt; user.email &lt;span class="s2"&gt;"your.email@example.com"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 4: Set Your Default Editor
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# For VS Code users&lt;/span&gt;
git config &lt;span class="nt"&gt;--global&lt;/span&gt; core.editor &lt;span class="s2"&gt;"code --wait"&lt;/span&gt;

&lt;span class="c"&gt;# For Nano (simpler for beginners)&lt;/span&gt;
git config &lt;span class="nt"&gt;--global&lt;/span&gt; core.editor &lt;span class="s2"&gt;"nano"&lt;/span&gt;

&lt;span class="c"&gt;# For Vim (if you're brave)&lt;/span&gt;
git config &lt;span class="nt"&gt;--global&lt;/span&gt; core.editor &lt;span class="s2"&gt;"vim"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 5: Check Your Configuration
&lt;/h3&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;You should see your name, email, and editor settings.&lt;/p&gt;




&lt;h2&gt;
  
  
  Part 3: Your First Git Repository
&lt;/h2&gt;

&lt;p&gt;A &lt;strong&gt;repository&lt;/strong&gt; (or "repo") is simply a folder that Git is watching. Let's create one.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 1: Create a Project
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Create a new folder&lt;/span&gt;
&lt;span class="nb"&gt;mkdir &lt;/span&gt;my-first-git-project
&lt;span class="nb"&gt;cd &lt;/span&gt;my-first-git-project

&lt;span class="c"&gt;# Create a file&lt;/span&gt;
&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"# My First Git Project"&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; README.md
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 2: Initialize Git
&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;p&gt;You'll see: &lt;code&gt;Initialized empty Git repository in /path/to/my-first-git-project/.git/&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Git created a hidden &lt;code&gt;.git&lt;/code&gt; folder. This is Git's brain—it stores all the history. Never touch this folder directly.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 3: Check Your Status
&lt;/h3&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;You'll see:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight console"&gt;&lt;code&gt;&lt;span class="go"&gt;On branch main

No commits yet

Untracked files:
&lt;/span&gt;&lt;span class="gp"&gt;  (use "git add &amp;lt;file&amp;gt;&lt;/span&gt;...&lt;span class="s2"&gt;" to include in what will be committed)
&lt;/span&gt;&lt;span class="go"&gt;        README.md

nothing added to commit but untracked files present
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is your most important command. &lt;code&gt;git status&lt;/code&gt; tells you exactly what's happening.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 4: Stage Your File
&lt;/h3&gt;



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

&lt;/div&gt;



&lt;p&gt;Now run &lt;code&gt;git status&lt;/code&gt; again:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight diff"&gt;&lt;code&gt;&lt;span class="p"&gt;Changes to be committed:
&lt;/span&gt;  (use "git rm --cached &amp;lt;file&amp;gt;..." to unstage)
        new file:   README.md
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The file has moved from "Working Directory" to "Staging Area".&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 5: Commit Your File
&lt;/h3&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;"Initial commit: add README"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You'll see:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight console"&gt;&lt;code&gt;&lt;span class="go"&gt;[main (root-commit) abc1234] Initial commit: add README
 1 file changed, 1 insertion(+)
 create mode 100644 README.md
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Congratulations! You've made your first commit. Your file is now safely in Git's repository.&lt;/p&gt;




&lt;h2&gt;
  
  
  Part 4: The Core Workflow You'll Use Every Day
&lt;/h2&gt;

&lt;p&gt;Now that you've made one commit, let's learn the daily rhythm of Git.&lt;/p&gt;

&lt;h3&gt;
  
  
  The Basic Cycle
&lt;/h3&gt;

&lt;p&gt;Every time you work on your project, you'll repeat this cycle:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;1. Make changes → 2. Stage changes → 3. Commit changes
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 1: Make Some Changes
&lt;/h3&gt;

&lt;p&gt;Open &lt;code&gt;README.md&lt;/code&gt; and add more content:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;&lt;span class="gh"&gt;# My First Git Project&lt;/span&gt;

This is my first project using Git for version control.

&lt;span class="gu"&gt;## What I've Learned&lt;/span&gt;
&lt;span class="p"&gt;-&lt;/span&gt; How to initialize a repository
&lt;span class="p"&gt;-&lt;/span&gt; How to stage files
&lt;span class="p"&gt;-&lt;/span&gt; How to make commits
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 2: Check What Changed
&lt;/h3&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;You'll see:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight diff"&gt;&lt;code&gt;&lt;span class="p"&gt;Changes not staged for commit:
&lt;/span&gt;  (use "git add &amp;lt;file&amp;gt;..." to update what will be committed)
        modified:   README.md
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 3: See the Actual Changes
&lt;/h3&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;This shows exactly what changed:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight diff"&gt;&lt;code&gt;&lt;span class="gh"&gt;diff --git a/README.md b/README.md
index abc1234..def5678 100644
&lt;/span&gt;&lt;span class="gd"&gt;--- a/README.md
&lt;/span&gt;&lt;span class="gi"&gt;+++ b/README.md
&lt;/span&gt;&lt;span class="p"&gt;@@ -1 +1,7 @@&lt;/span&gt;
 # My First Git Project
&lt;span class="gi"&gt;+
+This is my first project using Git for version control.
+
+## What I've Learned
+- How to initialize a repository
+- How to stage files
+- How to make commits
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The green lines with &lt;code&gt;+&lt;/code&gt; are additions. (Red lines with &lt;code&gt;-&lt;/code&gt; would be deletions.)&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 4: Stage and Commit
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git add README.md
git commit &lt;span class="nt"&gt;-m&lt;/span&gt; &lt;span class="s2"&gt;"Add description and learning notes"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  The Shortcut: Skip Staging
&lt;/h3&gt;

&lt;p&gt;If you want to commit all changes to tracked files without 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 commit &lt;span class="nt"&gt;-a&lt;/span&gt; &lt;span class="nt"&gt;-m&lt;/span&gt; &lt;span class="s2"&gt;"Commit all changes to tracked files"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;-a&lt;/code&gt; flag stages and commits in one step. But be careful—it won't include new files (untracked files).&lt;/p&gt;




&lt;h2&gt;
  
  
  Part 5: Viewing History – Your Time Machine
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Step 1: See Your Commit History
&lt;/h3&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;You'll see something like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight console"&gt;&lt;code&gt;&lt;span class="gp"&gt;commit def5678 (HEAD -&amp;gt;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;main&lt;span class="o"&gt;)&lt;/span&gt;
&lt;span class="gp"&gt;Author: Your Name &amp;lt;your.email@example.com&amp;gt;&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="go"&gt;Date:   Mon May 17 10:30:45 2026 -0400

    Add description and learning notes

commit abc1234
&lt;/span&gt;&lt;span class="gp"&gt;Author: Your Name &amp;lt;your.email@example.com&amp;gt;&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="go"&gt;Date:   Mon May 17 10:15:22 2026 -0400

    Initial commit: add README
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 2: See a Compact History
&lt;/h3&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;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def5678 (HEAD -&amp;gt; main) Add description and learning notes
abc1234 Initial commit: add README
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The first 7 characters (def5678, abc1234) are commit IDs—unique identifiers for each commit.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 3: See a Graph of Branches
&lt;/h3&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;--all&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This shows branches visually. We'll cover branches soon.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 4: See Who Changed What
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git blame README.md
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This shows who last modified each line—incredibly useful when you need to ask someone about code they wrote.&lt;/p&gt;




&lt;h2&gt;
  
  
  Part 6: Undoing Things – Your Safety Net
&lt;/h2&gt;

&lt;p&gt;Everyone makes mistakes. Git gives you multiple ways to undo.&lt;/p&gt;

&lt;h3&gt;
  
  
  Scenario 1: You Staged the Wrong File
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git add wrong-file.txt  &lt;span class="c"&gt;# Oops, didn't mean to add this&lt;/span&gt;
git status  &lt;span class="c"&gt;# Shows it's staged&lt;/span&gt;
git restore &lt;span class="nt"&gt;--staged&lt;/span&gt; wrong-file.txt  &lt;span class="c"&gt;# Unstage it&lt;/span&gt;
git status  &lt;span class="c"&gt;# Now it's unstaged (changes still exist)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Scenario 2: You Want to Discard Changes to a File
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# You made changes but want to go back to last commit&lt;/span&gt;
git restore wrong-file.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Warning:&lt;/strong&gt; This permanently discards uncommitted changes. Use with caution!&lt;/p&gt;

&lt;h3&gt;
  
  
  Scenario 3: You Committed Too Early (Forgot a File)
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git add forgotten-file.txt
git commit &lt;span class="nt"&gt;--amend&lt;/span&gt; &lt;span class="nt"&gt;-m&lt;/span&gt; &lt;span class="s2"&gt;"Add forgotten file to previous commit"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This adds the file to the previous commit instead of creating a new one. Perfect for when you forget something small.&lt;/p&gt;

&lt;h3&gt;
  
  
  Scenario 4: You Want to Undo a Commit but Keep Changes
&lt;/h3&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;This undoes the last commit but keeps your changes staged. The &lt;code&gt;HEAD~1&lt;/code&gt; means "go back one commit."&lt;/p&gt;

&lt;h3&gt;
  
  
  Scenario 5: You Want to Completely Undo a Commit
&lt;/h3&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;&lt;strong&gt;DANGER ZONE:&lt;/strong&gt; This completely removes the last commit AND all its changes. They're gone forever. Use only if you're absolutely sure.&lt;/p&gt;

&lt;h3&gt;
  
  
  Scenario 6: You Want to Revert a Commit (Safest)
&lt;/h3&gt;



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

&lt;/div&gt;



&lt;p&gt;This creates a &lt;em&gt;new&lt;/em&gt; commit that undoes the changes from commit &lt;code&gt;def5678&lt;/code&gt;. Safer than &lt;code&gt;reset&lt;/code&gt; because it doesn't rewrite history.&lt;/p&gt;




&lt;h2&gt;
  
  
  Part 7: Branching – Working in Parallel Universes
&lt;/h2&gt;

&lt;p&gt;Branches are Git's superpower. They let you work on multiple things simultaneously without them interfering.&lt;/p&gt;

&lt;h3&gt;
  
  
  The Mental Model
&lt;/h3&gt;

&lt;p&gt;Think of branches as alternate timelines:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;main&lt;/strong&gt; — The official, stable timeline&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;feature-login&lt;/strong&gt; — A parallel universe where you build login&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;bugfix-header&lt;/strong&gt; — Another universe where you fix the header&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;When you're done, you merge these timelines back together.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 1: Create a Branch
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Create a new branch called "feature/add-contact-page"&lt;/span&gt;
git branch feature/add-contact-page
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 2: Switch to Your Branch
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git checkout feature/add-contact-page
&lt;span class="c"&gt;# Or in modern Git:&lt;/span&gt;
git switch feature/add-contact-page
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 3: Create and Switch in One Command
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git checkout &lt;span class="nt"&gt;-b&lt;/span&gt; feature/add-about-page
&lt;span class="c"&gt;# Or:&lt;/span&gt;
git switch &lt;span class="nt"&gt;-c&lt;/span&gt; feature/add-about-page
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 4: See All Branches
&lt;/h3&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;The &lt;code&gt;*&lt;/code&gt; shows your current branch:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  feature/add-contact-page
* feature/add-about-page
  main
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 5: Work on Your Branch
&lt;/h3&gt;

&lt;p&gt;Create a new file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"# About Us"&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; about.md
git add about.md
git commit &lt;span class="nt"&gt;-m&lt;/span&gt; &lt;span class="s2"&gt;"Add about page"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This commit exists ONLY on your branch. Switch back to main and you won't see it.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 6: Switch Back to Main
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git checkout main
&lt;span class="c"&gt;# Or:&lt;/span&gt;
git switch main
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Look for &lt;code&gt;about.md&lt;/code&gt;—it's not there! Each branch has its own timeline.&lt;/p&gt;




&lt;h2&gt;
  
  
  Part 8: Merging – Bringing It All Together
&lt;/h2&gt;

&lt;p&gt;When your feature is done, you merge it back into main.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 1: Make Sure You're on the Destination Branch
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git checkout main
&lt;span class="c"&gt;# Or:&lt;/span&gt;
git switch main
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 2: Merge Your Feature
&lt;/h3&gt;



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

&lt;/div&gt;



&lt;p&gt;You'll see:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight console"&gt;&lt;code&gt;&lt;span class="go"&gt;Updating abc1234..def5678
Fast-forward
 about.md | 1 +
 1 file changed, 1 insertion(+)
 create mode 100644 about.md
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 3: Delete the Feature Branch (Optional)
&lt;/h3&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/add-about-page
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The branch is gone, but its commits are now part of main.&lt;/p&gt;




&lt;h2&gt;
  
  
  Part 9: Merge Conflicts – When Parallel Universes Collide
&lt;/h2&gt;

&lt;p&gt;Sometimes two branches modify the same part of the same file. Git doesn't know which change to keep—that's a &lt;strong&gt;merge conflict&lt;/strong&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 1: Create a Conflict (On Purpose)
&lt;/h3&gt;

&lt;p&gt;Let's create a situation where conflicts happen:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# On main branch&lt;/span&gt;
&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Line 1: Hello"&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; conflict.txt
git add conflict.txt
git commit &lt;span class="nt"&gt;-m&lt;/span&gt; &lt;span class="s2"&gt;"Add conflict.txt on main"&lt;/span&gt;

&lt;span class="c"&gt;# Create and switch to a new branch&lt;/span&gt;
git checkout &lt;span class="nt"&gt;-b&lt;/span&gt; test-branch
&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Line 1: Hola"&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; conflict.txt  &lt;span class="c"&gt;# Change same line&lt;/span&gt;
git add conflict.txt
git commit &lt;span class="nt"&gt;-m&lt;/span&gt; &lt;span class="s2"&gt;"Change conflict.txt on branch"&lt;/span&gt;

&lt;span class="c"&gt;# Switch back to main&lt;/span&gt;
git checkout main
&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Line 1: Bonjour"&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; conflict.txt  &lt;span class="c"&gt;# Change same line differently&lt;/span&gt;
git add conflict.txt
git commit &lt;span class="nt"&gt;-m&lt;/span&gt; &lt;span class="s2"&gt;"Change conflict.txt on main"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 2: Try to Merge
&lt;/h3&gt;



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

&lt;/div&gt;



&lt;p&gt;You'll see:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight console"&gt;&lt;code&gt;&lt;span class="go"&gt;Auto-merging conflict.txt
CONFLICT (content): Merge conflict in conflict.txt
&lt;/span&gt;&lt;span class="gp"&gt;Automatic merge failed;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;fix conflicts and &lt;span class="k"&gt;then &lt;/span&gt;commit the result.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 3: Look at the Conflicted File
&lt;/h3&gt;

&lt;p&gt;Open &lt;code&gt;conflict.txt&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight diff"&gt;&lt;code&gt;&lt;span class="gd"&gt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt; HEAD
&lt;/span&gt;&lt;span class="p"&gt;Line 1: Bonjour
&lt;/span&gt;&lt;span class="gh"&gt;=======
&lt;/span&gt;&lt;span class="p"&gt;Line 1: Hola
&lt;/span&gt;&lt;span class="gi"&gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt; test-branch
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt; HEAD&lt;/code&gt; to &lt;code&gt;=======&lt;/code&gt; is your current branch's version&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;=======&lt;/code&gt; to &lt;code&gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt; test-branch&lt;/code&gt; is the incoming branch's version&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Step 4: Resolve the Conflict
&lt;/h3&gt;

&lt;p&gt;Edit the file to what you want. For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Line 1: Hello World! (We decided to change it)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 5: Mark as Resolved
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git add conflict.txt
git commit &lt;span class="nt"&gt;-m&lt;/span&gt; &lt;span class="s2"&gt;"Resolve merge conflict in conflict.txt"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The merge is complete!&lt;/p&gt;




&lt;h2&gt;
  
  
  Part 10: Working with Remote Repositories (GitHub)
&lt;/h2&gt;

&lt;p&gt;Local Git is great, but the real magic happens when you collaborate using platforms like GitHub, GitLab, or Bitbucket.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 1: Create a Repository on GitHub
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Go to &lt;a href="https://github.com" rel="noopener noreferrer"&gt;github.com&lt;/a&gt; and sign in&lt;/li&gt;
&lt;li&gt;Click the "+" icon → "New repository"&lt;/li&gt;
&lt;li&gt;Name it "my-first-git-project"&lt;/li&gt;
&lt;li&gt;Don't initialize with README (we already have one)&lt;/li&gt;
&lt;li&gt;Click "Create repository"&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Step 2: Connect Your Local Repo to GitHub
&lt;/h3&gt;

&lt;p&gt;GitHub will show you commands. Run:&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 https://github.com/YOUR-USERNAME/my-first-git-project.git
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This tells Git: "There's a remote repository called 'origin' at this URL."&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 3: Push Your Code to GitHub
&lt;/h3&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 main
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;-u&lt;/code&gt; sets up tracking so future pushes can just use &lt;code&gt;git push&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 4: Check GitHub
&lt;/h3&gt;

&lt;p&gt;Refresh your GitHub page. Your code is now online!&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 5: Pull Changes from GitHub
&lt;/h3&gt;

&lt;p&gt;If someone else pushes changes, or you work on another computer:&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 origin main
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This downloads and merges changes from GitHub.&lt;/p&gt;




&lt;h2&gt;
  
  
  Part 11: The Daily Developer Workflow
&lt;/h2&gt;

&lt;p&gt;Here's what your actual day-to-day workflow looks like:&lt;/p&gt;

&lt;h3&gt;
  
  
  Morning: Start Fresh
&lt;/h3&gt;



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

&lt;/div&gt;



&lt;h3&gt;
  
  
  Work on a New Feature
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git checkout &lt;span class="nt"&gt;-b&lt;/span&gt; feature/awesome-thing
&lt;span class="c"&gt;# Write code...&lt;/span&gt;
git add &lt;span class="nb"&gt;.&lt;/span&gt;
git commit &lt;span class="nt"&gt;-m&lt;/span&gt; &lt;span class="s2"&gt;"Add awesome feature part 1"&lt;/span&gt;
&lt;span class="c"&gt;# Write more code...&lt;/span&gt;
git add &lt;span class="nb"&gt;.&lt;/span&gt;
git commit &lt;span class="nt"&gt;-m&lt;/span&gt; &lt;span class="s2"&gt;"Finish awesome feature"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Update Your Branch with Latest Changes
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git checkout main
git pull origin main
git checkout feature/awesome-thing
git merge main
&lt;span class="c"&gt;# Fix any conflicts&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Push and Create Pull Request
&lt;/h3&gt;



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

&lt;/div&gt;



&lt;p&gt;Then on GitHub, create a Pull Request for your feature.&lt;/p&gt;




&lt;h2&gt;
  
  
  Part 12: Handy Shortcuts and Aliases
&lt;/h2&gt;

&lt;p&gt;Git has many shortcuts that save time:&lt;/p&gt;

&lt;h3&gt;
  
  
  Staging Shortcuts
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Stage all changes (including new files)&lt;/span&gt;
git add &lt;span class="nt"&gt;-A&lt;/span&gt;

&lt;span class="c"&gt;# Stage all changes in current directory&lt;/span&gt;
git add &lt;span class="nb"&gt;.&lt;/span&gt;

&lt;span class="c"&gt;# Interactive staging (choose what to stage)&lt;/span&gt;
git add &lt;span class="nt"&gt;-p&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Commit Shortcuts
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Amend last commit (if you forgot something small)&lt;/span&gt;
git commit &lt;span class="nt"&gt;--amend&lt;/span&gt;

&lt;span class="c"&gt;# Commit with a shorter message flag&lt;/span&gt;
git commit &lt;span class="nt"&gt;-m&lt;/span&gt; &lt;span class="s2"&gt;"Message"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Log Shortcuts
&lt;/h3&gt;



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

&lt;span class="c"&gt;# Graph view&lt;/span&gt;
git log &lt;span class="nt"&gt;--graph&lt;/span&gt; &lt;span class="nt"&gt;--oneline&lt;/span&gt; &lt;span class="nt"&gt;--all&lt;/span&gt;

&lt;span class="c"&gt;# Last 3 commits&lt;/span&gt;
git log &lt;span class="nt"&gt;-3&lt;/span&gt;

&lt;span class="c"&gt;# Search commits by message&lt;/span&gt;
git log &lt;span class="nt"&gt;--grep&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"bug fix"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Create Aliases (Even Shorter!)
&lt;/h3&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; alias.co checkout
git config &lt;span class="nt"&gt;--global&lt;/span&gt; alias.br branch
git config &lt;span class="nt"&gt;--global&lt;/span&gt; alias.st status
git config &lt;span class="nt"&gt;--global&lt;/span&gt; alias.hist &lt;span class="s2"&gt;"log --oneline --graph --all"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now you can 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 st        &lt;span class="c"&gt;# Instead of git status&lt;/span&gt;
git co main   &lt;span class="c"&gt;# Instead of git checkout main&lt;/span&gt;
git hist      &lt;span class="c"&gt;# Pretty history view&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Part 13: The .gitignore File – What Not to Save
&lt;/h2&gt;

&lt;p&gt;Some files should NEVER be in Git:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Passwords and secrets&lt;/li&gt;
&lt;li&gt;Environment variables&lt;/li&gt;
&lt;li&gt;Build outputs (like &lt;code&gt;node_modules&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;Temporary files&lt;/li&gt;
&lt;li&gt;IDE settings&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Step 1: Create .gitignore
&lt;/h3&gt;



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

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 2: Add Patterns to Ignore
&lt;/h3&gt;

&lt;p&gt;Edit &lt;code&gt;.gitignore&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight conf"&gt;&lt;code&gt;&lt;span class="c"&gt;# Dependencies
&lt;/span&gt;&lt;span class="n"&gt;node_modules&lt;/span&gt;/
&lt;span class="n"&gt;vendor&lt;/span&gt;/

&lt;span class="c"&gt;# Build outputs
&lt;/span&gt;&lt;span class="n"&gt;dist&lt;/span&gt;/
&lt;span class="n"&gt;build&lt;/span&gt;/
*.&lt;span class="n"&gt;exe&lt;/span&gt;
*.&lt;span class="n"&gt;dll&lt;/span&gt;

&lt;span class="c"&gt;# Environment files
&lt;/span&gt;.&lt;span class="n"&gt;env&lt;/span&gt;
.&lt;span class="n"&gt;env&lt;/span&gt;.&lt;span class="n"&gt;local&lt;/span&gt;

&lt;span class="c"&gt;# IDE files
&lt;/span&gt;.&lt;span class="n"&gt;vscode&lt;/span&gt;/
.&lt;span class="n"&gt;idea&lt;/span&gt;/
*.&lt;span class="n"&gt;swp&lt;/span&gt;

&lt;span class="c"&gt;# OS files
&lt;/span&gt;.&lt;span class="n"&gt;DS_Store&lt;/span&gt;
&lt;span class="n"&gt;Thumbs&lt;/span&gt;.&lt;span class="n"&gt;db&lt;/span&gt;

&lt;span class="c"&gt;# Logs
&lt;/span&gt;*.&lt;span class="n"&gt;log&lt;/span&gt;
&lt;span class="n"&gt;npm&lt;/span&gt;-&lt;span class="n"&gt;debug&lt;/span&gt;.&lt;span class="n"&gt;log&lt;/span&gt;*
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 3: Add and Commit
&lt;/h3&gt;



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

&lt;/div&gt;



&lt;p&gt;Git will now ignore all those files automatically.&lt;/p&gt;




&lt;h2&gt;
  
  
  Part 14: Fixing Common Mistakes
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Mistake 1: Committed to the Wrong Branch
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# You committed to main but meant to commit to feature&lt;/span&gt;
git checkout &lt;span class="nt"&gt;-b&lt;/span&gt; feature-branch  &lt;span class="c"&gt;# Creates branch at current commit&lt;/span&gt;
git checkout main
git reset &lt;span class="nt"&gt;--hard&lt;/span&gt; HEAD~1  &lt;span class="c"&gt;# Remove commit from main&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Mistake 2: Need to Undo a Merge
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# If you haven't pushed yet&lt;/span&gt;
git reset &lt;span class="nt"&gt;--hard&lt;/span&gt; ORIG_HEAD

&lt;span class="c"&gt;# ORIG_HEAD is Git's backup of where you were before the merge&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Mistake 3: Committed with Wrong Message
&lt;/h3&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;span class="nt"&gt;-m&lt;/span&gt; &lt;span class="s2"&gt;"Correct message"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Mistake 4: Accidentally Deleted a File
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Restore a deleted file from the last commit&lt;/span&gt;
git restore deleted-file.txt

&lt;span class="c"&gt;# Or from a specific commit&lt;/span&gt;
git restore &lt;span class="nt"&gt;--source&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;abc1234 deleted-file.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Mistake 5: Need to See What Changed in a Commit
&lt;/h3&gt;



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

&lt;/div&gt;






&lt;h2&gt;
  
  
  Part 15: A Complete Real-World Example
&lt;/h2&gt;

&lt;p&gt;Let's walk through a realistic feature development cycle:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Start fresh&lt;/span&gt;
git checkout main
git pull origin main

&lt;span class="c"&gt;# Create feature branch&lt;/span&gt;
git checkout &lt;span class="nt"&gt;-b&lt;/span&gt; feature/user-authentication

&lt;span class="c"&gt;# Create new files&lt;/span&gt;
&lt;span class="nb"&gt;mkdir&lt;/span&gt; &lt;span class="nt"&gt;-p&lt;/span&gt; src/components
&lt;span class="nb"&gt;touch &lt;/span&gt;src/components/LoginForm.js
&lt;span class="nb"&gt;touch &lt;/span&gt;src/components/RegisterForm.js

&lt;span class="c"&gt;# Stage and commit&lt;/span&gt;
git add src/components/LoginForm.js
git commit &lt;span class="nt"&gt;-m&lt;/span&gt; &lt;span class="s2"&gt;"Add login form component"&lt;/span&gt;

git add src/components/RegisterForm.js
git commit &lt;span class="nt"&gt;-m&lt;/span&gt; &lt;span class="s2"&gt;"Add registration form component"&lt;/span&gt;

&lt;span class="c"&gt;# Oops, forgot to add styles&lt;/span&gt;
&lt;span class="nb"&gt;touch &lt;/span&gt;src/components/LoginForm.css
git add src/components/LoginForm.css
git commit &lt;span class="nt"&gt;--amend&lt;/span&gt; &lt;span class="nt"&gt;--no-edit&lt;/span&gt;  &lt;span class="c"&gt;# Add to previous commit&lt;/span&gt;

&lt;span class="c"&gt;# Meanwhile, main has been updated. Get those changes.&lt;/span&gt;
git checkout main
git pull origin main
git checkout feature/user-authentication
git merge main

&lt;span class="c"&gt;# Fix any conflicts, then continue&lt;/span&gt;
&lt;span class="c"&gt;# Add authentication logic&lt;/span&gt;
&lt;span class="nb"&gt;touch &lt;/span&gt;src/utils/auth.js
git add src/utils/auth.js
git commit &lt;span class="nt"&gt;-m&lt;/span&gt; &lt;span class="s2"&gt;"Add authentication utility functions"&lt;/span&gt;

&lt;span class="c"&gt;# Push and create pull request&lt;/span&gt;
git push origin feature/user-authentication
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Part 16: Git Cheat Sheet (Keep This Handy)
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Getting Started
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git init                    &lt;span class="c"&gt;# Create new repo&lt;/span&gt;
git clone &amp;lt;url&amp;gt;             &lt;span class="c"&gt;# Copy existing repo&lt;/span&gt;
git config &lt;span class="nt"&gt;--global&lt;/span&gt; user.name &lt;span class="s2"&gt;"Name"&lt;/span&gt;  &lt;span class="c"&gt;# Set identity&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Daily Work
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git status                  &lt;span class="c"&gt;# What's happening?&lt;/span&gt;
git add &amp;lt;file&amp;gt;              &lt;span class="c"&gt;# Stage file&lt;/span&gt;
git add &lt;span class="nb"&gt;.&lt;/span&gt;                   &lt;span class="c"&gt;# Stage all&lt;/span&gt;
git commit &lt;span class="nt"&gt;-m&lt;/span&gt; &lt;span class="s2"&gt;"message"&lt;/span&gt;     &lt;span class="c"&gt;# Commit staged&lt;/span&gt;
git commit &lt;span class="nt"&gt;-a&lt;/span&gt; &lt;span class="nt"&gt;-m&lt;/span&gt; &lt;span class="s2"&gt;"message"&lt;/span&gt;  &lt;span class="c"&gt;# Stage+commit tracked files&lt;/span&gt;
git pull                    &lt;span class="c"&gt;# Get latest changes&lt;/span&gt;
git push                    &lt;span class="c"&gt;# Send your changes&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Branches
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git branch                  &lt;span class="c"&gt;# List branches&lt;/span&gt;
git branch &amp;lt;name&amp;gt;           &lt;span class="c"&gt;# Create branch&lt;/span&gt;
git checkout &amp;lt;name&amp;gt;         &lt;span class="c"&gt;# Switch branch&lt;/span&gt;
git checkout &lt;span class="nt"&gt;-b&lt;/span&gt; &amp;lt;name&amp;gt;      &lt;span class="c"&gt;# Create and switch&lt;/span&gt;
git merge &amp;lt;name&amp;gt;            &lt;span class="c"&gt;# Merge branch into current&lt;/span&gt;
git branch &lt;span class="nt"&gt;-d&lt;/span&gt; &amp;lt;name&amp;gt;        &lt;span class="c"&gt;# Delete branch&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  History and Diff
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git log                     &lt;span class="c"&gt;# Show history&lt;/span&gt;
git log &lt;span class="nt"&gt;--oneline&lt;/span&gt;           &lt;span class="c"&gt;# Compact history&lt;/span&gt;
git diff                    &lt;span class="c"&gt;# Show unstaged changes&lt;/span&gt;
git diff &lt;span class="nt"&gt;--staged&lt;/span&gt;          &lt;span class="c"&gt;# Show staged changes&lt;/span&gt;
git show &amp;lt;commit&amp;gt;           &lt;span class="c"&gt;# Show commit details&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Undoing
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git restore &amp;lt;file&amp;gt;          &lt;span class="c"&gt;# Discard changes&lt;/span&gt;
git restore &lt;span class="nt"&gt;--staged&lt;/span&gt; &amp;lt;file&amp;gt; &lt;span class="c"&gt;# Unstage&lt;/span&gt;
git reset &lt;span class="nt"&gt;--soft&lt;/span&gt; HEAD~1     &lt;span class="c"&gt;# Undo commit, keep changes&lt;/span&gt;
git reset &lt;span class="nt"&gt;--hard&lt;/span&gt; HEAD~1     &lt;span class="c"&gt;# Undo commit, discard changes&lt;/span&gt;
git revert &amp;lt;commit&amp;gt;         &lt;span class="c"&gt;# Create undo commit&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Remote
&lt;/h3&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;span class="c"&gt;# Show remotes&lt;/span&gt;
git remote add origin &amp;lt;url&amp;gt; &lt;span class="c"&gt;# Add remote&lt;/span&gt;
git push &lt;span class="nt"&gt;-u&lt;/span&gt; origin main     &lt;span class="c"&gt;# First push&lt;/span&gt;
git pull origin main        &lt;span class="c"&gt;# Get changes&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  What You've Learned
&lt;/h2&gt;

&lt;p&gt;Congratulations! You now know enough Git to be productive. Let's review:&lt;/p&gt;

&lt;h3&gt;
  
  
  Core Concepts
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;[ ] Git tracks snapshots, not differences&lt;/li&gt;
&lt;li&gt;[ ] Three states: Working → Staged → Committed&lt;/li&gt;
&lt;li&gt;[ ] Commits are permanent snapshots with messages&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Essential Commands
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;[ ] &lt;code&gt;git init&lt;/code&gt; — Create repository&lt;/li&gt;
&lt;li&gt;[ ] &lt;code&gt;git add&lt;/code&gt; — Stage changes&lt;/li&gt;
&lt;li&gt;[ ] &lt;code&gt;git commit&lt;/code&gt; — Save permanently&lt;/li&gt;
&lt;li&gt;[ ] &lt;code&gt;git status&lt;/code&gt; — Check what's happening&lt;/li&gt;
&lt;li&gt;[ ] &lt;code&gt;git log&lt;/code&gt; — View history&lt;/li&gt;
&lt;li&gt;[ ] &lt;code&gt;git diff&lt;/code&gt; — See changes&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Branching
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;[ ] Branches are parallel universes&lt;/li&gt;
&lt;li&gt;[ ] &lt;code&gt;git branch&lt;/code&gt; to create/ list&lt;/li&gt;
&lt;li&gt;[ ] &lt;code&gt;git checkout&lt;/code&gt; to switch&lt;/li&gt;
&lt;li&gt;[ ] &lt;code&gt;git merge&lt;/code&gt; to combine&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Collaboration
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;[ ] &lt;code&gt;git push&lt;/code&gt; to share&lt;/li&gt;
&lt;li&gt;[ ] &lt;code&gt;git pull&lt;/code&gt; to get updates&lt;/li&gt;
&lt;li&gt;[ ] &lt;code&gt;git clone&lt;/code&gt; to copy a repo&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Safety
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;[ ] How to undo mistakes&lt;/li&gt;
&lt;li&gt;[ ] How to resolve conflicts&lt;/li&gt;
&lt;li&gt;[ ] When to use &lt;code&gt;.gitignore&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Next Steps
&lt;/h2&gt;

&lt;p&gt;You've mastered the basics. Here's what to learn next:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Interactive Rebase&lt;/strong&gt; — Clean up commit history before sharing&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Cherry-picking&lt;/strong&gt; — Apply specific commits to other branches&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Stashing&lt;/strong&gt; — Temporarily save uncommitted work&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Git Hooks&lt;/strong&gt; — Automate tasks with scripts&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Git Flow&lt;/strong&gt; — A branching strategy for teams&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Forking Workflow&lt;/strong&gt; — Contributing to open source&lt;/li&gt;
&lt;/ol&gt;




&lt;h2&gt;
  
  
  Resources
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://git-scm.com/doc" rel="noopener noreferrer"&gt;Git Official Documentation&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://ohshitgit.com" rel="noopener noreferrer"&gt;Oh Shit, Git!&lt;/a&gt; — When things go wrong&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://learngitbranching.js.org" rel="noopener noreferrer"&gt;Learn Git Branching&lt;/a&gt; — Interactive tutorial&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://skills.github.com" rel="noopener noreferrer"&gt;GitHub Skills&lt;/a&gt; — Free courses&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Final Words of Wisdom
&lt;/h2&gt;

&lt;p&gt;From someone who's used Git for over a decade:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;You will make mistakes.&lt;/strong&gt; Everyone does. The beauty of Git is that almost nothing is permanent. There's almost always a way to recover.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Commit often.&lt;/strong&gt; A commit is a save point. Save early, save often. I commit every time I complete a small logical piece of work.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Write good commit messages.&lt;/strong&gt; Future you will thank present you. A good message explains &lt;em&gt;why&lt;/em&gt;, not just &lt;em&gt;what&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Branch freely.&lt;/strong&gt; Branches are cheap and easy. Create them for everything—features, bug fixes, experiments.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Pull before you push.&lt;/strong&gt; Always get the latest changes before pushing your own. It avoids conflicts.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Git is a tool, not a religion.&lt;/strong&gt; Use what works for you and your team. The "right" way is whatever keeps your code safe and your team happy.&lt;/p&gt;




&lt;p&gt;That junior developer who cried over lost code? That was me. I've never lost code since learning Git. Now you won't either.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Enjoyed this tutorial? I'm **Alexander Merveille&lt;/em&gt;* from &lt;strong&gt;Marvelbiz Solutions&lt;/strong&gt;, a &lt;strong&gt;Senior Software Engineer&lt;/strong&gt; and &lt;strong&gt;1-on-1 private Instructor.&lt;/strong&gt; I write about development tools and workflows every Month. Follow me on X &lt;a href="https://x.com/@themarvelbiz" rel="noopener noreferrer"&gt;@themarvelbiz&lt;/a&gt; . Check out my website &lt;a href="https://gemsalex.com" rel="noopener noreferrer"&gt;Alexander Merveille portfolio&lt;/a&gt; . And if you have a Git horror story, we've all been there!*&lt;/p&gt;




</description>
      <category>devops</category>
      <category>git</category>
      <category>github</category>
      <category>versioning</category>
    </item>
  </channel>
</rss>
