DevOps Engineering Version Control03 / 21

SECTION 02 · 30 MIN READ & EXPLORE

Git: recover, branch, and merge

Recover a missing player, resolve a tactical conflict, and distinguish staging from committing.

Git records snapshots. The working tree, staging area, and committed history can each contain a different version of a file.

Local, remote, and your changes

Use the board to trace cloning, pushing, and pulling between a local and a remote repository. The three boxes below distinguish the working directory, staging area, and commit history.

EXPLORE THE DIAGRAM

Git: local, remote, and the three areas

Experiment freely. Changes disappear when you reset or refresh.

Preview of Git: local, remote, and the three areas

Course material

These exercises come from the original course repository. The mission below keeps the original instructions.

Download the lesson files, extract them, and run the initializer inside the extracted 00-git-101 directory. It creates the can-2025-morocco practice repository.

bash setup.sh
cd can-2025-morocco
cat README.md

Explore the files

setup.sh

#!/bin/bash

# 1. Initialize the CAN 2025 Project
mkdir can-2025-morocco
cd can-2025-morocco
git init -b main

# Configure dummy identity for the "Previous Assistant Coach"
git config user.email "assistant@frmf.ma"
git config user.name "Assistant Coach"

# 2. Initial Setup: Host Cities and Stadiums
mkdir infrastructure
echo "- Rabat: Prince Moulay Abdellah" > infrastructure/stadiums.txt
echo "- Casablanca: Stade Mohammed V" >> infrastructure/stadiums.txt
echo "- Tangier: Ibn Batouta" >> infrastructure/stadiums.txt
echo "- Marrakech: Grand Stade" >> infrastructure/stadiums.txt
git add .
git commit -m "Setup: Confirmed host cities for CAN 2025"

# 3. Squad Selection (The "Good" State)
echo "GK: Yassine Bounou" > starting_xi.txt
echo "DF: Achraf Hakimi" >> starting_xi.txt
echo "DF: Nayef Aguerd" >> starting_xi.txt
echo "MF: Sofyan Amrabat" >> starting_xi.txt
echo "FW: Brahim Diaz" >> starting_xi.txt
echo "FW: Soufiane Rahimi" >> starting_xi.txt
git add starting_xi.txt
git commit -m "Squad: Registered official player list"

# 4. The Disaster: Accidental Deletion of Star Player
# (Simulating deleting a critical file)
grep -v "Hakimi" starting_xi.txt > starting_xi_temp.txt && mv starting_xi_temp.txt starting_xi.txt
git add starting_xi.txt
git commit -m "Update: Adjusted defensive line (Oops)"

# 5. Parallel Strategy (Branching)
# Create a new branch for an experimental attacking formation
git checkout -b strategy/attack-overload
echo "Formation: 4-3-3 Attack" > tactics.txt
echo "Instruction: High Pressing" >> tactics.txt
git add tactics.txt
git commit -m "Tactics: Defined attacking strategy for Group Stage"

# 6. Conflict Setup (Back on Main)
git checkout main
echo "Formation: 5-4-1 Park the Bus" > tactics.txt
git add tactics.txt
git commit -m "Tactics: Defined defensive strategy for Opening Match"

# 7. Create the Mission Instructions (README)
cat <<'EOT' > README.md
# 🦁 Operation Atlas Lions: CAN 2025 DevOps Edition

**Location:** Prince Moulay Abdellah Stadium, Rabat.
**Time:** T-Minus 2 Hours to Kickoff.
**Status:** TACTICAL CHAOS.

## 📋 Mission Objectives (Git Exercises)

### Task 1: The Missing Star (Git Log & Checkout)
The previous assistant accidentally removed **Achraf Hakimi** from the `starting_xi.txt`.
1. Run `git log` to find the commit where the squad was "Registered official player list".
2. Find the **Commit Hash**.
3. Bring the file back from the past using: 
   `git checkout <COMMIT_HASH> -- starting_xi.txt`
4. Verify Hakimi is back in the file.
5. Commit the fix: `git commit -am "Fix: Restored Hakimi to starting XI"`.

### Task 2: The Tactical Merge (Branching & Merging)
We have a divergent strategy. The main branch wants to play defensive ("Park the Bus"), but the fans want the attacking style from the `strategy/attack-overload` branch.
1. We decide to go with the ATTACK.
2. Merge the attacking branch into main:
   `git merge strategy/attack-overload`
3. **CONFLICT ALERT!** Both branches created `tactics.txt` with different content.
4. Open `tactics.txt`. You will see conflict markers (`<<<<<<`, `======`, `>>>>>>`).
5. Delete the defensive lines and keep the **Attacking** lines. Remove the markers.
6. Save the file and finalize the merge:
   `git add tactics.txt`
   `git commit -m "Merge: Finalized attacking formation"`

### Task 3: The Last Minute Change (Staging)
The coach wants to add a motivational quote to the locker room.
1. Create a file `locker_room.md` and add: "Dima Maghrib!".
2. Add it to the staging area: `git add locker_room.md`.
3. **Wait!** The coach changed his mind. Unstage the file (do not delete it, just remove from staging):
   `git restore --staged locker_room.md`
   
**Good luck. The stadium is full. Don't crash the server (or the match).**
EOT

git add README.md
git commit -m "Docs: Printed tactical instructions for the new Engineer"

echo "-----------------------------------------------------------"
echo "   🇲🇦 CAN 2025 Repository Ready!"
echo "   Folder: can-2025-morocco"
echo "   Mission: Fix the squad before kickoff."
echo "-----------------------------------------------------------"
HANDS-ON LAB

🦁 Operation Atlas Lions: CAN 2025 DevOps Edition

Location: Prince Moulay Abdellah Stadium, Rabat. Time: T-Minus 2 Hours to Kickoff. Status: TACTICAL CHAOS.

📋 Mission Objectives (Git Exercises)

Task 1: The Missing Star (Git Log & Checkout)

The previous assistant accidentally removed Achraf Hakimi from the starting_xi.txt.

  1. Run git log to find the commit where the squad was “Registered official player list”.
  2. Find the Commit Hash.
  3. Bring the file back from the past using: git checkout <COMMIT_HASH> -- starting_xi.txt
  4. Verify Hakimi is back in the file.
  5. Commit the fix: git commit -am "Fix: Restored Hakimi to starting XI".
Task 2: The Tactical Merge (Branching & Merging)

We have a divergent strategy. The main branch wants to play defensive (“Park the Bus”), but the fans want the attacking style from the strategy/attack-overload branch.

  1. We decide to go with the ATTACK.
  2. Merge the attacking branch into main: git merge strategy/attack-overload
  3. CONFLICT ALERT! Both branches created tactics.txt with different content.
  4. Open tactics.txt. You will see conflict markers (<<<<<<, ======, >>>>>>).
  5. Delete the defensive lines and keep the Attacking lines. Remove the markers.
  6. Save the file and finalize the merge: git add tactics.txt git commit -m "Merge: Finalized attacking formation"
Task 3: The Last Minute Change (Staging)

The coach wants to add a motivational quote to the locker room.

  1. Create a file locker_room.md and add: “Dima Maghrib!”.
  2. Add it to the staging area: git add locker_room.md.
  3. Wait! The coach changed his mind. Unstage the file (do not delete it, just remove from staging): git restore --staged locker_room.md

Good luck. The stadium is full. Don’t crash the server (or the match).

Download lesson files
CHECK YOUR UNDERSTANDING

Pause and predict

If you unstage a file, will your edits disappear?

Try your own explanation first. These notes stay on this page and are not saved or graded.

Show explanation

No. git restore --staged changes the index; the working file remains available to edit.

A LITTLE CLEARER?

Take a moment to explain the idea in your own words.

Progress is saved in this browser.

DevOps Engineering

Course overview ↗

01Introduction to DevOps

  1. What is DevOps?20m
  2. DevOps Roles20m