Day 2: Basic Git Workflow

Basic Git Workflow

The Three-Stage Workflow

Git’s power comes from its three-stage workflow that gives you complete control over what gets committed:

  1. Modified: Files changed in working directory
  2. Staged: Files marked for next commit
  3. Committed: Files permanently stored in Git history

Essential Commands in Action

Creating and Tracking Files:

bash

# Create a new file
echo "# My Awesome Project" > README.md
echo "print('Hello, Git!')" > main.py

# Check what Git sees
git status

# Stage files for commit
git add README.md
git add main.py
# Or stage all files at once
git add .

# Create your first commit
git commit -m "Initial commit: Add README and main script"

Understanding Git Status:

bash

# Detailed status information
git status --long

# Concise status format
git status --short

# See what's staged vs unstaged
git diff            # Shows unstaged changes
git diff --staged   # Shows staged changes

Viewing Project History

bash

# Basic commit history
git log

# Compact one-line format
git log --oneline

# Visual branch representation
git log --graph --oneline --all

# Show changes in each commit
git log -p

Undoing Changes

Before Staging:

bash

# Discard changes in working directory
git checkout -- filename.txt
# Or using newer syntax
git restore filename.txt

After Staging:

bash

# Unstage a file
git reset HEAD filename.txt
# Or using newer syntax
git restore --staged filename.txt

Hands-On Exercise: Create a small Python calculator project. Practice the add-commit cycle, view history, and experiment with undoing changes.

You Might Also Like

Related guides