Git Commit: The Complete Beginner's Guide
A commit is the fundamental unit of Git history. This guide explains what happens when you commit, how to write useful messages, and how to fix mistakes: everything a beginner needs to build good habits from day one.
Beginner9 min readUpdated
What is a Git commit?
A Git commit is a snapshot of your staged changes saved permanently in the repository's history. Each commit has a unique SHA hash, an author, a timestamp, and a message describing what changed.
The short version
- 1Stage changes:
git add <file>orgit add . - 2Create the commit:
git commit -m 'your message' - 3Verify:
git log --oneline - 4Amend if needed (before pushing):
git commit --amend
Why it matters
You've heard you should 'commit often', but you're not sure what a commit actually is, how to write a good message, or what to do when you realise your last commit was wrong.
Every commit is a permanent snapshot in your project's history. Good commits make bugs easier to track down, code easier to review, and history easier to understand weeks or months later. Bad commits (vague messages, giant diffs, mixed concerns) turn your history into noise.
Where it usually goes wrong
- Writing commit messages like 'fix', 'wip', or 'stuff'
- Committing everything in one giant dump instead of logical units
- Forgetting to stage files before committing
- Not knowing how to amend a commit after the fact
Git commit, step by step
Step 1: Stage your changes first
Before you can commit, you need to stage the changes you want to include. Nothing unstaged will appear in the commit.
Terminalgit add src/app.ts# or stage everything:git add .Tip: Run
git statusfirst to see what's changed and what's already staged.Step 2: Create a commit with a message
The
-mflag lets you write your commit message inline. Keep it short (under 72 characters) and describe *what* changed and *why*, not *how*.Terminalgit commit -m "add login form validation"Step 3: Write a multi-line commit message
For larger changes, use a short subject line followed by a blank line and a more detailed body. Running
git commitwithout-mopens your configured editor.Terminalgit commit# In your editor:# Add login form validation## - Validate email format on blur# - Show inline error messages# - Disable submit button until form is validTip: The subject line should complete the sentence: 'If applied, this commit will...'
Step 4: Stage and commit in one step
The
-aflag auto-stages all tracked modified files and commits them. It does not include new (untracked) files.Terminalgit commit -a -m "fix typo in header"Careful:
git commit -askips the staging area. Use it only when you're sure you want to commit every change in every tracked file.In Gitoryx: See staged vs unstaged files clearly before committingHow it works Step 5: Amend the last commit
Made a typo in your message, or forgot to include a file? You can rewrite the last commit as long as it hasn't been pushed yet.
Terminal# Fix the commit messagegit commit --amend -m "add login form validation with email check"# Add a forgotten file to the last commitgit add src/validation.tsgit commit --amend --no-editCareful: Never amend a commit that has already been pushed to a shared branch. It rewrites history and will cause problems for your teammates.
Step 6: View your commit history
Use
git logto see past commits. The--onelineflag gives a compact view.Terminalgit log --oneline# a3f2c1d add login form validation# 9b1e4fa init project structure# 7c0d2ae initial commit
Mistakes to avoid with git commit
- Vague commit messages
- 'fix', 'update', 'changes': these messages tell you nothing when you're debugging three months later.
- Fix: Write messages that answer: what changed, and why? Example: 'fix null pointer in user login when session expires'.
- One massive commit for unrelated changes
- Mixing a bug fix, a refactor, and a new feature in one commit makes history hard to read and reverts painful.
- Fix: Use
git add -pto split changes into separate, focused commits. - Amending already-pushed commits
- Amending rewrites the commit SHA. If that commit is on a shared branch, teammates will face a diverged history.
- Fix: Only amend commits that exist only in your local branch, or use
git revertfor pushed commits.
Git commit in Gitoryx
Gitoryx shows your full commit history as a visual graph, making it easy to see what each commit changed, who made it, and how branches diverge over time.
- See staged vs unstaged files clearly before committing
- Visual commit graph shows your history at a glance
- One-click amend for the last commit
- Commit message templates to enforce team conventions
Free plan · no account required · macOS, Windows and Linux
Git commit: frequently asked questions
- What is the difference between `git add` and `git commit`?
git addmoves changes into the staging area.git commitsaves the staged changes as a permanent snapshot in the repository history. You always need togit addbeforegit commit.- How do I undo my last commit without losing my changes?
- Use
git reset --soft HEAD~1. This removes the last commit but keeps all changes staged, so you can re-commit them with a corrected message. - What should a good commit message look like?
- A good subject line is under 72 characters, written in the imperative mood ('add feature' not 'added feature'), and describes what the commit does. For complex changes, add a blank line and a body with more context.
- Can I commit only some files?
- Yes. Stage only the files you want with
git add <file>, then commit. Files you didn't stage won't be included.
Related reading
- How to Undo a Commit in Git (The Right Way)Tutorial · 10 min
- Git Commit Conventions: Conventional Commits & GitmojiTutorial · 11 min