Script Valley
Git and GitHub Complete Course: From Beginner to Advanced
Introduction to Version Control and Git BasicsLesson 1.4

Staging and Committing Changes

git add, git commit, commit message, git log, staged changes, untracked files

Staging and Committing Changes

Committing is the act of saving a snapshot of your staged changes to the repository history. Every commit captures a point in time you can return to later.

DiagramGit Staging and Commit Workflow

IMAGE PROMPT (replace this block with your generated image):

Flat workflow diagram on white background. Title: Git Add and Commit Workflow. Left side: a box labeled Modified Files with three file icons (readme.md, index.js, style.css) each with orange edit dots. Center: a box labeled Staging Area (light #3A5EFF fill). Shows only readme.md and index.js moved in (green checkmarks). style.css remains outside with label Not staged. Arrow from files to staging labeled git add readme.md index.js in #3A5EFF badge. Right side: a commit object box labeled Repository (solid #3A5EFF fill, white text) showing commit hash abc1234, message Add initial structure, author and date fields. Arrow from staging to repo labeled git commit -m "...". Below the repo box: a stacked timeline of commit circles: C1 ← C2 ← C3 (HEAD) connected by arrows. Small annotation: git log --oneline showing the three commits. White background, monospace for code, sans-serif for labels.

Staging Files

To stage a single file, run git add filename.txt. To stage all changes at once, run git add . (the dot means the current directory and everything inside it).

Staging gives you control. You can stage only the files relevant to one logical change and commit them, leaving other work in progress unstaged. This keeps your history clean and meaningful.

Creating a Commit

Once files are staged, commit them:

git commit -m "Add initial project structure"

The -m flag lets you write the commit message inline. Always write messages in the imperative mood and keep them under 72 characters. Good examples: Fix login bug, Add user authentication, Update README with setup instructions.

Viewing Commit History

Run git log to see all commits in the current branch. Each entry shows the commit hash, author, date, and message. For a compact view, use git log --oneline. To see a graphical branch history, use git log --oneline --graph --all.

Amending the Last Commit

If you made a typo in your last commit message or forgot to include a file, amend it before pushing:

git commit --amend -m "Corrected commit message"

Only amend commits that have not been pushed to a shared repository.

Up next

Ignoring Files with .gitignore

Sign in to track progress