Thuta Learning
ExercisesDevOps & Toolsbeginner

Exercise: Git Basics Commands Practice

Relax. We'll talk through this in plain words — no textbook voice.

What you'll walk away with

  • Practice Exercise: Git Basics Commands Practice yourself, hands-on
  • Practice the skills you've already learned and make them solid
  • Get good at finding mistakes, fixing them, and checking your own work

Let's think about it this way for a second

This exercise set is meant as a quick self-test of the core skills you learned in the Basics chapter — initializing a repository, staging, committing, and ignoring files. It won't teach any new concepts; instead, it's about getting more fluent with the commands you've already learned through repetition. We recommend opening a terminal and actually running each task hands-on.

Exercises

Task 1: Create a new folder called 'my-notes', run git init, create a file called notes.txt, and commit it with the message 'Initial notes'. Task 2: Add two more lines to notes.txt, use git diff to look at the changes before committing, then commit. Task 3: Create a file called temp.log, add *.log to .gitignore, and confirm with git status that temp.log isn't being tracked. Task 4: Review the full commit history with git log --oneline.

Code Example

bash
# Task 1
mkdir my-notes
cd my-notes
git init
echo "Meeting notes" > notes.txt
git add notes.txt
git commit -m "Initial notes"

# Task 2
echo "Follow up with team" >> notes.txt
echo "Review PR by Friday" >> notes.txt
git diff
git add notes.txt
git commit -m "Add follow-up items"

# Task 3
echo "debug output" > temp.log
printf "*.log\n" >> .gitignore
git status

# Task 4
git log --oneline
You should see
After Task 4, git log --oneline shows two commits, and temp.log no longer appears anywhere in the git status output.

Try it in 5 minutes

Instead of notes.txt, create a new file called second-notes.txt and redo Tasks 1-4 all over again from scratch (5 minutes).

A quick word of caution

Once a file has already been tracked with git add, just adding it to .gitignore won't untrack it — you need to untrack it first with git rm --cached <file>.

Easy traps

  • Running git commit directly without running git add notes.txt first, and hitting a 'nothing to commit' error
  • Creating .gitignore but temp.log keeps being tracked anyway because it was already staged with git add . before .gitignore was created

Now try it yourself

Instead of notes.txt, create a new file called second-notes.txt and redo Tasks 1-4 all over again from scratch (5 minutes).

You'll know it worked when: After Task 4, git log --oneline shows two commits, and temp.log no longer appears anywhere in the git status output.

Exercise: Git Basics Commands Practice | Thuta Learning