-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathdemo-script.sh
More file actions
executable file
·485 lines (371 loc) · 12.4 KB
/
demo-script.sh
File metadata and controls
executable file
·485 lines (371 loc) · 12.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
#!/bin/bash
# Demo Script for Git & GitHub Team Workflow Workshop
# This script demonstrates key concepts through live examples
set -e
# Color codes for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
MAGENTA='\033[0;35m'
CYAN='\033[0;36m'
NC='\033[0m' # No Color
# Function to print section headers
print_header() {
echo ""
echo -e "${CYAN}════════════════════════════════════════════════════════════${NC}"
echo -e "${CYAN} $1${NC}"
echo -e "${CYAN}════════════════════════════════════════════════════════════${NC}"
echo ""
}
# Function to print commands before executing
print_command() {
echo -e "${YELLOW}$${NC} ${GREEN}$1${NC}"
}
# Function to pause for explanation
pause() {
echo ""
echo -e "${MAGENTA}[Press Enter to continue...]${NC}"
read -r
}
# Function to show step description
describe_step() {
echo ""
echo -e "${BLUE}→ $1${NC}"
echo ""
}
# Setup temporary demo directory
DEMO_DIR="/tmp/git-team-workflow-demo-$$"
mkdir -p "$DEMO_DIR"
cd "$DEMO_DIR"
# Introduction
clear
print_header "Git & GitHub Team Workflow - Live Demo"
echo "This demo will walk you through a complete team workflow:"
echo " 1. Creating issues"
echo " 2. Branch-based development"
echo " 3. Pull requests"
echo " 4. Merge conflicts"
echo " 5. Team collaboration"
echo ""
echo "📁 Demo directory: $DEMO_DIR"
pause
# Demo 1: Repository Setup
print_header "Demo 1: Repository Setup"
describe_step "Initialize a new Git repository"
print_command "git init demo-project"
git init demo-project
cd demo-project
print_command "git config user.name 'Demo User'"
git config user.name "Demo User"
print_command "git config user.email 'demo@example.com'"
git config user.email "demo@example.com"
describe_step "Create initial project files"
cat > README.md << 'EOF'
# Team Project Demo
This is a demo repository for learning team Git workflows.
EOF
print_command "cat README.md"
cat README.md
print_command "git add README.md"
git add README.md
print_command "git commit -m 'Initial commit: Add README'"
git commit -m "Initial commit: Add README"
print_command "git log --oneline"
git log --oneline
pause
# Demo 2: Feature Branch Workflow
print_header "Demo 2: Feature Branch Workflow"
describe_step "Create a feature branch for adding a login feature"
print_command "git checkout -b feature/user-login"
git checkout -b feature/user-login
print_command "git branch # Shows all branches with * on current"
git branch
describe_step "Develop the login feature"
cat > login.js << 'EOF'
// User Login Functionality
function login(username, password) {
console.log('Logging in user:', username);
// Validate inputs
if (!username || !password) {
throw new Error('Username and password required');
}
// Authenticate
return authenticateUser(username, password);
}
function authenticateUser(username, password) {
// Placeholder authentication logic
return { success: true, user: username };
}
EOF
print_command "cat login.js # Review the code"
cat login.js
describe_step "Make a commit for this feature"
print_command "git add login.js"
git add login.js
print_command "git commit -m 'feat: add user login functionality'"
git commit -m "feat: add user login functionality"
print_command "git log --oneline --graph --all"
git log --oneline --graph --all
pause
# Demo 3: Multiple Feature Branches
print_header "Demo 3: Multiple Features in Parallel"
describe_step "Switch back to main and create another feature branch"
print_command "git checkout main"
git checkout main
print_command "git checkout -b feature/user-profile"
git checkout -b feature/user-profile
cat > profile.js << 'EOF'
// User Profile Management
function getUserProfile(userId) {
console.log('Fetching profile for user:', userId);
return {
id: userId,
name: 'Demo User',
email: 'demo@example.com'
};
}
function updateProfile(userId, updates) {
console.log('Updating profile:', userId, updates);
return { success: true };
}
EOF
print_command "git add profile.js"
git add profile.js
print_command "git commit -m 'feat: add user profile management'"
git commit -m "feat: add user profile management"
describe_step "View all branches and their commits"
print_command "git log --oneline --graph --all --decorate"
git log --oneline --graph --all --decorate
pause
# Demo 4: Merging Features
print_header "Demo 4: Merging Features"
describe_step "Merge the login feature into main"
print_command "git checkout main"
git checkout main
print_command "git merge feature/user-login"
git merge feature/user-login -m "Merge feature/user-login into main"
print_command "git log --oneline --graph"
git log --oneline --graph
describe_step "Now merge the profile feature"
print_command "git merge feature/user-profile"
git merge feature/user-profile -m "Merge feature/user-profile into main"
print_command "git log --oneline --graph --all"
git log --oneline --graph --all
describe_step "Clean up merged branches"
print_command "git branch -d feature/user-login"
git branch -d feature/user-login
print_command "git branch -d feature/user-profile"
git branch -d feature/user-profile
print_command "git branch # Show remaining branches"
git branch
pause
# Demo 5: Creating a Merge Conflict
print_header "Demo 5: Handling Merge Conflicts"
describe_step "Create two branches that will conflict"
print_command "git checkout -b feature/update-readme-1"
git checkout -b feature/update-readme-1
cat > README.md << 'EOF'
# Team Project Demo
This is a demo repository for learning team Git workflows.
## Features
- User authentication system
- Profile management
EOF
print_command "git add README.md"
git add README.md
print_command "git commit -m 'docs: add features section to README'"
git commit -m "docs: add features section to README"
describe_step "Go back to main and create another conflicting branch"
print_command "git checkout main"
git checkout main
print_command "git checkout -b feature/update-readme-2"
git checkout -b feature/update-readme-2
cat > README.md << 'EOF'
# Team Project Demo
This is a demo repository for learning team Git workflows.
## Getting Started
1. Clone the repository
2. Run the application
EOF
print_command "git add README.md"
git add README.md
print_command "git commit -m 'docs: add getting started section'"
git commit -m "docs: add getting started section"
pause
describe_step "Merge first branch - this will work fine"
print_command "git checkout main"
git checkout main
print_command "git merge feature/update-readme-1"
git merge feature/update-readme-1 -m "Merge feature/update-readme-1"
print_command "cat README.md # See the merged content"
cat README.md
describe_step "Try to merge second branch - this will create a conflict!"
print_command "git merge feature/update-readme-2"
set +e # Don't exit on error
git merge feature/update-readme-2 2>&1 | tee merge_output.txt
MERGE_STATUS=$?
set -e
if [ $MERGE_STATUS -ne 0 ]; then
echo ""
echo -e "${RED}⚔️ Merge conflict detected!${NC}"
echo ""
describe_step "Check the status to see what's conflicted"
print_command "git status"
git status
describe_step "Look at the conflict markers in the file"
print_command "cat README.md"
echo ""
cat README.md
echo ""
describe_step "Resolve the conflict by keeping both changes"
cat > README.md << 'EOF'
# Team Project Demo
This is a demo repository for learning team Git workflows.
## Features
- User authentication system
- Profile management
## Getting Started
1. Clone the repository
2. Run the application
EOF
print_command "cat README.md # Show resolved version"
cat README.md
describe_step "Mark conflict as resolved and complete the merge"
print_command "git add README.md"
git add README.md
print_command "git commit -m 'merge: resolve README conflict by including both sections'"
git commit -m "merge: resolve README conflict by including both sections"
echo ""
echo -e "${GREEN}✓ Conflict resolved successfully!${NC}"
fi
pause
# Demo 6: Team Collaboration Simulation
print_header "Demo 6: Team Collaboration Scenario"
describe_step "Simulate three developers working simultaneously"
# Developer 1: Bug fix
print_command "git checkout -b hotfix/login-validation"
git checkout -b hotfix/login-validation
cat >> login.js << 'EOF'
// Enhanced validation
function validatePassword(password) {
if (password.length < 8) {
throw new Error('Password must be at least 8 characters');
}
return true;
}
EOF
git add login.js
git commit -m "fix: add password length validation"
echo -e "${BLUE}Developer 1 completed hotfix${NC}"
# Developer 2: New feature
print_command "git checkout main"
git checkout main
print_command "git checkout -b feature/logout"
git checkout -b feature/logout
cat > logout.js << 'EOF'
// Logout functionality
function logout() {
console.log('User logged out');
clearSession();
redirectToLogin();
}
function clearSession() {
// Clear user session
}
function redirectToLogin() {
// Redirect to login page
}
EOF
git add logout.js
git commit -m "feat: add logout functionality"
echo -e "${BLUE}Developer 2 completed feature${NC}"
# Developer 3: Refactoring
print_command "git checkout main"
git checkout main
print_command "git checkout -b refactor/auth-module"
git checkout -b refactor/auth-module
mkdir -p auth
cat > auth/index.js << 'EOF'
// Centralized authentication module
export { login } from './login.js';
export { logout } from './logout.js';
export { authenticateUser } from './auth.js';
EOF
git add auth/
git commit -m "refactor: create centralized auth module"
echo -e "${BLUE}Developer 3 completed refactoring${NC}"
pause
describe_step "Now integrate all changes (Team Lead coordinates)"
print_command "git checkout main"
git checkout main
echo ""
echo "Merging hotfix first (highest priority)..."
print_command "git merge hotfix/login-validation"
git merge hotfix/login-validation -m "Merge hotfix: login validation"
echo ""
echo "Merging logout feature..."
print_command "git merge feature/logout"
git merge feature/logout -m "Merge feature: logout"
echo ""
echo "Merging refactoring..."
print_command "git merge refactor/auth-module"
git merge refactor/auth-module -m "Merge refactor: auth module"
describe_step "View the final project history"
print_command "git log --oneline --graph --all"
git log --oneline --graph --all
describe_step "See all project files"
print_command "ls -la"
ls -la
print_command "tree -L 2 # If tree is installed"
tree -L 2 2>/dev/null || find . -maxdepth 2 -not -path '*/\.git/*' | sed 's|^\./||' | sort
pause
# Demo 7: Best Practices Summary
print_header "Demo 7: Best Practices Demonstrated"
echo "✅ What we demonstrated:"
echo ""
echo "1. Branch-based workflow"
echo " • Created feature branches for each task"
echo " • Kept main branch stable"
echo ""
echo "2. Clear commit messages"
echo " • Used conventional commit format"
echo " • feat:, fix:, docs:, refactor: prefixes"
echo ""
echo "3. Merge conflict resolution"
echo " • Identified conflicts"
echo " • Resolved by combining changes"
echo " • Tested after resolution"
echo ""
echo "4. Team collaboration"
echo " • Multiple developers working in parallel"
echo " • Coordinated integration"
echo " • Priority-based merging"
echo ""
echo "5. Clean history"
echo " • Logical commit organization"
echo " • Deleted merged branches"
echo " • Clear project timeline"
echo ""
pause
# Cleanup
print_header "Demo Complete!"
echo "This demo covered the essential Git team workflow concepts."
echo ""
echo "📁 Demo files are in: $DEMO_DIR"
echo " (Feel free to explore or delete this directory)"
echo ""
echo "📚 Next steps:"
echo " 1. Try the hands-on exercises in ../exercises/hands-on-lab.md"
echo " 2. Practice these workflows in your own projects"
echo " 3. Experiment with GitHub features online"
echo ""
echo "🎓 Key commands to remember:"
echo " git branch <name> - Create a branch"
echo " git checkout -b <name> - Create and switch to branch"
echo " git merge <branch> - Merge branch into current"
echo " git log --oneline --graph - Visualize history"
echo " git status - Check repository state"
echo ""
echo -e "${GREEN}Happy collaborating! 🚀${NC}"
echo ""