Skip to main content

Basic Git Workflow - Add Commit Status

Now that you have Git installed and a repository created, it's time to learn the fundamental workflow you'll use every day. In this lesson, we'll explore how to track changes in your project using Git's core commands: add, commit, and status.

Learning Goals:

  • Understand the three main areas of Git: working directory, staging area, and repository
  • Use git status to check the state of your files
  • Stage changes with git add
  • Create commits with git commit
  • Write meaningful commit messages

Understanding Git's Three Areas

Git manages your files across three main areas:

  1. Working Directory - Where you make changes to your files
  2. Staging Area - Where you prepare changes for committing
  3. Repository - Where your committed changes are permanently stored

Think of it like packaging a shipment: you gather items (staging), box them up (committing), and store them in the warehouse (repository).

Checking Repository Status

The git status command shows you what's happening in your repository. It tells you which files are modified, staged, or untracked.

Let's create a simple project and see git status in action:

Create files and check status
# Create a new file
echo "# My Project" > README.md

# Check the repository status
git status

You'll see output similar to:

On branch main
Untracked files:
(use "git add <file>..." to include in what will be committed)
README.md

nothing added to commit but untracked files present (use "git add" to track)
tip

Run git status frequently! It's your best friend for understanding what Git sees and helping you avoid mistakes.

Staging Changes with git add

Before you can commit changes, you need to stage them using git add. Staging lets you choose exactly which changes to include in your next commit.

Stage files for committing
# Stage a specific file
git add README.md

# Or stage all changes in the current directory
git add .

# Check status again
git status

Now you'll see:

On branch main
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
new file: README.md

Creating Your First Commit

A commit is a snapshot of your staged changes. Each commit has a unique ID and includes your changes, author information, and a commit message.

Create a commit with a message
git commit -m "Add project README file"

After committing, git status will show:

On branch main
nothing to commit, working tree clean

Writing Good Commit Messages

Commit messages should be clear and descriptive. Follow these guidelines:

  • First line: brief summary (50 characters or less)
  • Blank line
  • Detailed explanation (if needed)
Good commit message example
git commit -m "Add user authentication feature

- Implement login form with validation
- Add password encryption
- Create session management"
warning

Avoid vague commit messages like "fix stuff" or "update files." Your future self (and teammates) will thank you for clear messages that explain the why behind changes.

Complete Workflow Example

Let's walk through a complete example of making multiple changes:

Create and modify files
# Create a new Python file
echo "print('Hello, Git!')" > hello.py

# Modify the README
echo "This project demonstrates Git workflow." >> README.md

# Check status
git status

Common Pitfalls

  • Forgetting to stage changes: Modified files won't be committed unless you git add them first
  • Committing too much at once: Break changes into logical commits - one feature or fix per commit
  • Bad commit messages: Write messages that explain what changed and why
  • Not checking status: Always run git status before committing to avoid surprises
  • Adding unnecessary files: Be selective about what you stage; don't use git add . blindly

Summary

You've now mastered Git's basic workflow:

  • Use git status to see the state of your files
  • Stage changes with git add to prepare them for committing
  • Create commits with git commit -m "message" to save snapshots
  • Write clear, descriptive commit messages

This add-commit-status cycle forms the foundation of all Git usage. Practice it until it becomes second nature!

Quiz

Tracking and Committing Changes – Quick Check

What does `git status` show you?

Question 1/5