Hands-on Lab

#Lab: Git Workflow Practice

Practice the complete Git workflow.

#🎯 Tasks

#1. Repository Setup

bash
1mkdir git-practice
2cd git-practice
3git init
4git config user.name "Your Name"
5git config user.email "you@example.com"

#2. Create First Commit

bash
echo "# My Project" > README.md
git add README.md
git commit -m "Initial commit"

#3. Feature Branch Workflow

bash
1# Create feature branch
2git checkout -b feature/add-config
3
4# Make changes
5echo "port: 8080" > config.yaml
6git add config.yaml
7git commit -m "feat: add configuration file"
8
9# Merge back
10git checkout main
11git merge feature/add-config
12git branch -d feature/add-config

#4. Simulate Conflict

bash
1# Create two branches
2git checkout -b branch-a
3echo "line from A" >> README.md
4git commit -am "Change from A"
5
6git checkout main
7git checkout -b branch-b
8echo "line from B" >> README.md
9git commit -am "Change from B"
10
11# Merge and resolve
12git checkout main
13git merge branch-a
14git merge branch-b  # Conflict!
15
16# Edit README.md to resolve, then:
17git add README.md
18git commit -m "Merge branch-b, resolve conflict"

#✅ Success Criteria

  • Repository initialized
  • Feature branch merged
  • Conflict resolved