Common mistakes and practice
35 min · Beginner
Need help? Ask a tutor on WhatsApp (opens in a new tab)Fix the mistakes
The slips that cost marks in this module. Spot each one, then check the fix.
Most Git trouble comes from a few repeated slips: a command in the wrong folder, the wrong files staged, or a misread git status. Each one has a clear message and a clear fix.
The everyday loop
Every change you save with Git follows the same short loop. git status is the step people skip, and it prevents most mistakes. Commit small, finished steps, each with a clear message: they are easy to read, revert and amend.
Mistakes and fixes at a glance
The most common first error: the terminal is not inside the project folder, so Git finds no .git folder. Nothing is wrong with the repository.
Example 1 · Git outside the repository
Runs in: Your terminal
git statusfatal: not a git repository (or any of the parent directories): .git
What this code does
- The prompt shows the home folder, which only contains
marks-report. Git looked here and in every folder above and found no.git. - Fix:
cd marks-report, then rungit statusagain. Never answer this error withgit initin the wrong folder.
The other common slips, each with the message you see and the fix:
Author identity unknown→ setuser.nameanduser.emailwithgit config --global. Review: Why version control? (opens in a new tab)no changes added to commit→ nothing is staged;git addfirst. Review: Your first repository (opens in a new tab)git diffprints nothing aftergit add→ the change is staged;git diff --staged. Review: History and differences (opens in a new tab)- An edit you want gone →
git restore <file>; a file staged by mistake →git restore --staged <file>. Review: Undoing changes (opens in a new tab) - A pushed commit is wrong →
git revert <id>, never amend or reset it. Review: Undoing changes (opens in a new tab) - An ignored file still shows as modified →
git rm --cachedit and commit. Review: .gitignore and secrets (opens in a new tab)
A careless git add .
Priya had no .gitignore yet. git add . staged her change to marks.txt, but also build/marks-report.zip and .env with the database password. Nothing is committed yet, so nothing leaked.
Example 2 · Unstage the wrong files
Runs in: Your terminal
git restore --staged build .envgit status -sM marks.txt ?? .env ?? build/
What this code does
git restore --stagedworks on folders too:buildand.envare back to untracked (??) and still on disk.- Only the real change,
M marks.txt, is still staged for the commit.
Next, a .gitignore with build/ and .env, so the same slip cannot happen again. If the secret had been committed but not pushed: git rm --cached .env and git commit --amend. If pushed: change the password first.
Reading a mixed status
Priya staged one change to marks.txt, then changed it again, edited README.md and created AUTHORS.txt. One short status shows all of it, and every letter matters before you commit.
git status -sMM marks.txt M README.md ?? AUTHORS.txt
MM marks.txt: the leftMis the staged change, the rightMa newer change that is not staged.M README.md: modified, not staged.?? AUTHORS.txt: new and untracked.- A commit now holds only the staged change to
marks.txt.git diff --stagedshows exactly that change.
Typos and wrong names
Git never guesses: a mistyped command or file name stops with a message that names the problem. Read its first line; Git even suggests the command you meant. Press Tab after the first letters of a file name to complete it.
git comit -m "Fix total"git add marks.txgit: 'comit' is not a git command. See 'git --help'. The most similar command is commit fatal: pathspec 'marks.tx' did not match any files
Module quiz
Questions from the whole module. Your first answer is your score.
Problems
Graded easy to hard, using everything from this module.
Try each one yourself first. Use the hint if you get stuck. Mark it as done when it works.
Exercise 1· Easy
Open PowerShell or Terminal in your home folder and run git status. It prints fatal: not a git repository. Fix it for your marks-report repository and check the status.
Runs in: Your terminal
On branch main nothing to commit, working tree clean
Exercise 2· Easy
Explain each line of this short status in plain words, and say what a commit made now would contain.
MM marks.txt M README.md?? AUTHORS.txtmarks.txt: one change staged, a newer change not staged README.md: modified, not staged AUTHORS.txt: new file, untracked A commit now contains only the staged change to marks.txt
Exercise 3· Medium
Create attendance.txt with the four lines Attended: 42, Total: 50, Percentage: 84% and Eligible for exam: yes (75% or more may write the exam). A personal notes.txt is also in the folder. Commit only the attendance file, with the message Add attendance sheet, then show the short status.
Runs in: Your terminal
[main 3a91c7e] Add attendance sheet 1 file changed, 4 insertions(+) create mode 100644 attendance.txt ?? notes.txt
Exercise 4· Medium
Create the mixed status from exercise 2 in your repository. Throw away both the staged and the unstaged change to marks.txt, but leave the other files alone. Show the short status and print the file.
Runs in: Your terminal
M README.md ?? AUTHORS.txt Total: 326 Average: 81
Exercise 5· Medium
With no .gitignore yet, make a build folder with one file in it, create .env and change marks.txt. Run git add .. Unstage build and .env, write a .gitignore with build/ and .env, stage it, and show the short status before committing.
Runs in: Your terminal
A .gitignore M marks.txt
Exercise 6· Medium
Your last commit Update English marks (not pushed) also committed db.properties, which holds a password. Remove the file from the commit but keep it on disk, ignore it from now on, keep the message, and show the files in the fixed commit.
Runs in: Your terminal
rm 'db.properties'
[main 417f0b4] Update English marks
Date: Mon Oct 19 10:20:00 2026 +0530
2 files changed, 2 insertions(+), 1 deletion(-)
create mode 100644 .gitignore
commit 417f0b411882f238582f52b8d620e1b6c6bb4713 (HEAD -> main)
Author: Priya Sharma <priya@example.com>
Date: Mon Oct 19 10:20:00 2026 +0530
Update English marks
.gitignore | 1 +
marks.txt | 2 +-
2 files changed, 2 insertions(+), 1 deletion(-)Exercise 7· Hard
Arjun's session is below. Name the four problems in order and the fix for each.
> git comit -m "Add fees"git: 'comit' is not a git command. See 'git --help'.> git commit -m "Add fees"no changes added to commit (use "git add" and/or "git commit -a")> git add fee.txtfatal: pathspec 'fee.txt' did not match any files> git add fees.txt> git commit -m "Add fees"Author identity unknown1. Typo: use git commit 2. Nothing staged: git add the file first 3. Wrong file name: the file is fees.txt (check with ls) 4. No identity: set user.name and user.email, then commit again
Exercise 8· Hard
Plan the commands, in order. Your last commit (local) says Add percentge. You also edited README.md by mistake and want that edit gone. A commit from last week, 49faf47, is already pushed and must be undone.
git commit --amend -m "Add percentage" git restore README.md git revert 49faf47
Interview questions
Questions interviewers ask on this topic.
What's next
You finished the preview of Git Basics
Python Programming has 21 sections, 110 modules and 609 lessons. An account opens every lesson and saves your progress.
Finish up
Mark complete & continue
Next: Branches: create one and switch to it