SkillNavora
Git & GitHub Complete Guide › Lesson 3 of 8 · about 20 minutes
Lesson 3

The daily Git loop: status, diff, add, commit, log, .gitignore and restore

The commands you will type every day, with real output: check what changed, stage, commit with a good message, read history, ignore files that should never be committed, and undo edits.

Checked against official sources in November 2026. Lessons build on each other.
In plain words. Your daily loop is: look (status, diff), choose (add), save (commit), and look back (log). Run git status whenever you are unsure; it always tells you where you are and what to do next.

Key ideas

git statusShows the branch, staged changes, unstaged changes and untracked files.
git diffShows line-by-line changes not yet staged (add --staged for staged ones).
git addStages a file's current content for the next commit.
git commit -mSaves staged changes as a commit with a message.
git logShows history; --oneline, --graph and --stat make it readable.
.gitignoreA list of files and folders Git should not track, such as secrets and build output.

How it works

1. A real day of work

Edit a file, create another, check, stage, commit and read history:

Real terminal output (captured when this guide was built)
$ printf '# My study notes\n\n## Git\n- commit = snapshot\n' > README.md
$ echo 'print("hello")' > hello.py
$ git status --short
 M README.md
?? hello.py
$ git diff
diff --git a/README.md b/README.md
index c430214..c76ade9 100644
--- a/README.md
+++ b/README.md
@@ -1 +1,4 @@
 # My study notes
+
+## Git
+- commit = snapshot
$ git add README.md hello.py
$ git diff --staged --stat
 README.md | 3 +++
 hello.py  | 1 +
 2 files changed, 4 insertions(+)
$ git commit -m "Add Git notes and a hello script"
[main e26a370] Add Git notes and a hello script
 2 files changed, 4 insertions(+)
 create mode 100644 hello.py
$ git log --oneline --stat -1
e26a370 Add Git notes and a hello script
 README.md | 3 +++
 hello.py  | 1 +
 2 files changed, 4 insertions(+)

2. Write commit messages people can use

  • Start with a verb in the present tense: Add, Fix, Update, Remove.
  • Say what and why in under about 60 characters: Fix login error when email has capitals.
  • One logical change per commit. If you need "and", consider two commits.
  • For longer explanations, run git commit without -m and write a blank line then a body.

3. Ignore what should never be committed

Secrets (.env files, keys), dependency folders (node_modules, .venv), build output and editor files belong in .gitignore.

Real terminal output (captured when this guide was built)
$ mkdir -p __pycache__ && echo x > __pycache__/hello.cpython-312.pyc && echo 'API_KEY=secret' > .env
$ git status --short
?? .env
?? __pycache__/
$ printf '__pycache__/\n.env\n' > .gitignore
$ git status --short
?? .gitignore
$ git add .gitignore && git commit -q -m "Ignore cache files and .env"
$ git check-ignore -v .env
.gitignore:2:.env	.env
A starter .gitignore
# .gitignore for a Python or data project
.env
*.key
__pycache__/
.venv/
.ipynb_checkpoints/
data/raw/          # large or private data
*.log
.DS_Store
Careful. If a secret was ever committed, adding it to .gitignore does not remove it from history. Revoke and rotate the secret immediately, then clean history (see Lesson 6).

4. Undo edits safely

Real terminal output (captured when this guide was built)
$ echo 'oops, wrong line' >> README.md
$ git status --short
 M README.md
$ git restore README.md
$ git status --short
$ echo 'draft' > draft.txt && git add draft.txt
$ git restore --staged draft.txt
$ git status --short
?? draft.txt
$ rm draft.txt
You want toCommand
Throw away unstaged edits in a filegit restore file
Unstage a file but keep the editsgit restore --staged file
See what you are about to commitgit diff --staged
Stage only parts of a filegit add -p file (answer y or n per change)

5. Read history like a pro

Real terminal output (captured when this guide was built)
$ git log --oneline --graph -8
* 1ee8249 Revert "Add a wrong fact"
* d586c73 Add a wrong fact
* 7800ea1 Add tag definition
* addeeb7 Add quiz question 3
* 209b3bc Add glossary
* 6478e23 Add quiz question 2
*   14bb0e2 Merge feature/title: keep both ideas in the title
|\  
| * 1670ef3 Rename notes title
$ git log --oneline --author=Ravi
addeeb7 Add quiz question 3
$ git log --oneline -S "remote"
addeeb7 Add quiz question 3
$ git blame -s quiz.md
1e3e254e 1) Q1: What is a commit?
6478e235 2) Q2: What does git add do?
addeeb77 3) Q3: What is a remote?
$ git show --stat --format='%h %an %s' HEAD~1
d586c73 Asha Learner Add a wrong fact

 glossary.md | 1 +
 1 file changed, 1 insertion(+)
  • --author filters by person, -S "text" finds commits that added or removed that text.
  • git blame shows which commit last changed each line.
  • git show shows one commit's message and changes.

Common mistakes and fixes

MistakeFix
git add . without lookingRun git status and git diff first; check nothing secret or huge is included.
Messages like "update" or "final final"Describe what changed and why.
Committing a .env fileAdd it to .gitignore before the first commit; if it leaked, rotate the secret.

Practice

  1. Make three small changes and commit them as three separate commits with clear messages.
  2. Create a .gitignore, add a fake .env and confirm git status ignores it.
  3. Use git log -S to find the commit that added a word you choose.

Quick check

What does git diff --staged show?

The changes that are staged and will go into the next commit.

Which command throws away unstaged edits to a file?

git restore

Does adding a file to .gitignore remove it from earlier commits?

No. It only stops tracking new changes; committed secrets must be rotated and history cleaned.

Go further (official sources)

Refer & earn