The Basic Git Workflow

The daily Git workflow follows a simple cycle: modify → stage → commit.

Creating a repository

bash
# Start a new project
mkdir my-project && cd my-project
git init

# Or clone an existing one
git clone https://github.com/user/repo.git

The three states

Files in Git exist in three states:

1. Modified — You changed the file but haven't told Git yet

2. Staged — You marked the file to be included in the next commit

3. Committed — The snapshot is safely stored in Git's database

Stage and commit

bash
# Check what's changed
git status

# Stage specific files
git add index.html style.css

# Stage everything
git add .

# Commit with a message
git commit -m "Add homepage layout and styles"

Viewing history

bash
# See commit history
git log --oneline

# See what changed in a specific commit
git show abc1234

# See differences not yet staged
git diff

Pro tip: Write good commit messages

Bad: git commit -m "fix"

Good: git commit -m "Fix login redirect for expired sessions"

A good commit message explains why something changed, not just what.