Skip to main content
March 23, 2026/5 min read

Stage & Commit Files: git add, git commit, & git log

Master Git Version Control with Essential Commands

What You'll Learn

This guide covers the essential Git workflow commands for staging, committing, and tracking changes in your codebase. Perfect for developers new to version control or looking to solidify their Git fundamentals.

Staging

Before making any commit, you must explicitly tell Git which files to include—whether they're new untracked files, modified existing files, or deleted files. This deliberate process is called staging and relies on the powerful add command. This selective approach isn't bureaucratic overhead; it's intelligent version control design. Consider a common scenario: you're simultaneously refactoring a complex component and fixing an unrelated bug. The bug fix is ready for production, but the refactoring needs more work. Git's staging area lets you commit the bug fix immediately while keeping the incomplete refactoring changes in your working directory. We add files to a staging area, then commit only what has been explicitly staged. Even file deletions must be tracked in Git's history—after all, removing the wrong file can be just as consequential as adding buggy code.

Git Workflow Components

Working Directory

Your local files where you make changes. Files here are either tracked or untracked by Git.

Staging Area

A preparation zone where you select which changes to include in your next commit.

Repository

The committed history of your project stored in the .git directory.

Check Status

Understanding your repository's current state is fundamental to effective Git workflow. Let's examine what's happening in your working directory.

1. In your terminal (Terminal, Git Bash, or Windows Command Prompt), navigate to the folder that contains your Git repository. 2. Enter this command:

git status

3. You'll see your current branch (likely main for repositories created in recent years, or master for older ones) and the status of all files: untracked files that Git doesn't know about, modified files that have changed since your last commit, and deleted files that have been removed from your working directory. We'll explore branching strategies in detail later, but for now, focus on understanding your file states.

Checking Repository Status

1

Navigate to Repository

Use terminal to navigate to your Git repository folder using the cd command

2

Run Status Command

Execute 'git status' to see current branch and file statuses

3

Interpret Results

Review which files are untracked, modified, or deleted and ready for staging

Stage Files to Prepare for Commit

Now that you understand your repository's current state, let's prepare your changes for commit. Staging gives you granular control over exactly what gets included in your commit history.

1. Enter one of the following commands, depending on your specific needs:

  • Stage all files: git add .
  • Stage a specific file: git add example.html (replace example.html with your actual file name)
  • Stage an entire folder: git add myfolder (replace myfolder with your folder path)

Professional considerations:

  • When file names or paths contain spaces, wrap them in quotes: git add "my file.html"
  • You can stage multiple items by repeating these commands or listing multiple files: git add file1.html file2.css
  • Use git add -p for interactive staging, allowing you to stage specific portions of files—invaluable when you've made multiple logical changes to a single file

2. Verify your staging actions by checking the status again:

git status

3. You should now see files listed under "Changes to be committed"—these are your staged changes, ready for the next commit.

Git Add Command Options

FeatureCommandPurpose
git add .Stage all filesQuick staging for all changes
git add filenameStage specific fileSelective staging control
git add foldernameStage entire folderOrganize by directory
Recommended: Use selective staging (git add filename) for better commit organization and cleaner history.

Unstage a File

Mistakes happen, and Git provides clean ways to correct them. If you accidentally stage something that shouldn't be in this commit, you can unstage it without losing your changes.

git reset HEAD example.html (replace example.html with your specific file or folder)

This command moves the file back to the "Changes not staged for commit" section, giving you the opportunity to stage it properly later or include it in a different commit entirely.

Unstaging Strategy

Use 'git reset HEAD filename' to unstage accidentally staged files. This removes files from staging area while keeping your working directory changes intact.

Deleting Files

File deletion in Git requires the same intentional approach as file addition. When you delete files using your operating system's file manager or command line, Git detects these deletions and shows them as "deleted" in git status. You must then stage these deletions using git add to include them in your next commit.

For a more streamlined approach, Git provides the rm command, which both deletes files from your working directory and stages the deletion in a single operation:

  • git rm example.html to remove a file and stage the deletion
  • git rm -r myfolder to recursively remove a folder and all its contents, staging everything for deletion

This approach ensures your working directory and staging area remain synchronized, reducing the chance of inconsistencies in your commit history.

File Deletion Methods

FeatureMethodSteps Required
Manual Delete + Git AddDelete file manuallyTwo-step process
Git RM CommandDelete and stage togetherOne-step process
Recommended: Use 'git rm' for efficiency - it deletes the file and stages the deletion in one command.

Commit Files

With your changes properly staged, you're ready to create a permanent snapshot in your project's history. Every commit should represent a logical, complete unit of work.

1. Create your commit with a descriptive message:

git commit -m "Message that describes what this change accomplishes"

Professional tip: Write commit messages in the imperative mood—"Fix user authentication bug" rather than "Fixed user authentication bug." This convention aligns with Git's own automatically generated commit messages and creates consistency across your project history. Think of each commit message as completing the sentence "If applied, this commit will..." When working in team environments, this approach makes code reviews and project archaeology significantly more effective.

2. Confirm your commit was successful by checking the repository status:

git status

3. A clean repository with no pending changes will display: nothing to commit, working tree clean.

Commit Message Best Practice

Write commit messages in imperative mood like 'Make headings blue' rather than past tense like 'Made headings blue'. This tells collaborators what your code will do when merged.

Making a Commit

1

Execute Commit

Run 'git commit -m "Your descriptive message"' to commit staged changes

2

Verify Clean State

Check status again to confirm all changes are committed successfully

3

Confirm Clean Tree

Look for 'nothing to commit, working tree clean' message indicating success

Fixing Your Last Commit Message

Even experienced developers occasionally write unclear or incorrect commit messages. Git's amend feature lets you correct your most recent commit message without creating additional history clutter.

git commit --amend -m "Put your corrected message here"

Important: Only amend commits that haven't been pushed to shared repositories. Amending commits that others have already pulled will create conflicts and complicate your team's workflow.

Amend Commit Caution

The 'git commit --amend' command modifies the last commit. Only use this for commits that haven't been pushed to shared repositories, as it rewrites Git history.

View a List of Commits

Understanding your project's evolution requires examining its commit history. Git provides several commands for viewing commits, each offering different levels of detail depending on your current needs.

  • For a concise overview of recent commits, use:
    • git log --oneline
  • For detailed commit information including author, date, and full messages:
    • git log

NOTE: When viewing lengthy commit histories, use the Down/Up Arrow keys to navigate and press Q to return to your command prompt.

  • For comprehensive information including which specific files changed in each commit:
    • git log --stat

NOTE: This detailed view is particularly useful during code reviews or when tracking down when specific changes were introduced. Use Down/Up Arrow keys to scroll and Q to quit.

Git Log Command Options

FeatureCommandInformation Displayed
git log --onelineSimplified viewCommit hash and message
git logStandard detailAuthor, date, full message
git log --statMaximum detailFiles changed and statistics
Recommended: Start with 'git log --oneline' for quick overview, use 'git log --stat' for detailed analysis.
Navigation Tip

When viewing long commit histories, use Arrow keys to scroll up and down, and press 'Q' to quit the log view and return to your command prompt.

Go Beyond Git

Mastering Git is just one component of modern software development expertise. Our comprehensive curriculum prepares professionals for today's demanding technical landscape through hands-on projects and expert instruction.

Key Takeaways

1Git staging area allows selective commits - you can choose exactly which files to commit rather than all modified files at once
2Always check git status before and after staging to understand your repository state and verify your actions
3Use git add with specific filenames for precise control, or git add . to stage all changes in the current directory
4Files must be staged before committing, including deleted files which need to be tracked in Git history
5Write commit messages in imperative mood to clearly communicate what the code will do when applied
6Git commit --amend allows you to fix your last commit message, but only use it before pushing to shared repositories
7Different git log commands provide varying levels of detail - choose based on how much information you need
8The git rm command efficiently deletes files and stages the deletion in one step, streamlining your workflow

RELATED ARTICLES