Skip to main content

Command Palette

Search for a command to run...

Surviving the Git Storm: A Complete DevOps Workflow

Updated
8 min read
Surviving the Git Storm: A Complete DevOps Workflow

In the world of DevOps, Git mastery is non-negotiable. This comprehensive tutorial walks through a realistic development scenario that starts from scratch and transforms common mistakes into a professional workflow. We'll experience merge conflicts, security issues, messy history, and emergency fixes—then systematically resolve them using industry-standard Git practices.

Phase 1: Project Setup & Initial Development

Step 1: Create Project and Initial Commit

Objective: Set up a new Git repository with proper structure and connect it to a remote repository.

Steps:

  1. Create project directory:
mkdir git-storm-project
cd git-storm-project
  1. Open in VS Code:
code .
  1. In VS Code terminal, initialize Git repository:
git init
  1. Create and verify project documentation:
echo "# Project Storm - User Management System" > README.md
ls -la

Explanation: The ls -la command verifies that README.md was created successfully.

  1. Make initial commit:
git add README.md
git commit -m "feat: initialize project with documentation"
  1. Verify the commit was created:
git log --oneline

You should see one commit with the message "feat: initialize project with documentation".

  1. Rename branch to main (if needed):
git branch -M main
  1. Connect to remote repository (create on GitHub/GitLab first):
git remote add origin https://github.com/Joel5040/Project-Storm.git
  1. Push to remote repository:
git push -u origin main

The -u flag sets upstream tracking so future pushes can use just git push.

Verification: Check your GitHub repository to confirm the files appear.

Step 2: Develop Feature with Common Mistakes

Objective: Create a feature branch and simulate typical development patterns including security mistakes.

Detailed Steps:

  1. Create and switch to feature branch:
git checkout -b feature/user-dashboard
  1. Create first component - normal development:
echo "console.log('User dashboard loaded');" > dashboard.js
git add dashboard.js
git commit -m "Add dashboard component"

  1. Create problematic commit with sensitive data:
echo "API_KEY=secret123456" > .env
echo "DB_PASSWORD=temp-password-123" >> .env
git add .env
git commit -m "Add environment configuration"

This simulates a common security mistake that we'll fix later.

  1. Create additional feature work:
mkdir src
echo "function getUserData() { return { name: 'John' }; }" > src/user.js
git add src/user.js
git commit -m "Implement user data functions"
  1. Verify your work:
git log --oneline

You should see 3 new commits on top of your initial commit.


Phase 2: Team Collaboration Challenges

Step 3: Simulate Teammate's Changes

Objective: Experience handling remote changes from other team members while working on a feature.

Detailed Steps:

  1. Switch to main branch:
git checkout main
  1. Simulate teammate adding project structure:
cat > index.html << 'EOF'
<!DOCTYPE html>
<html>
<head>
    <title>Project Storm</title>
</head>
<body>
    <!-- Navigation added by team -->
    <nav>Home | Dashboard | Profile</nav>
    <h1>Welcome to Project Storm</h1>
</body>
</html>
EOF

  1. Commit and push teammate's work:
git add index.html
git commit -m "feat: add basic website structure with navigation"
git push origin main
  1. Verify the remote is updated:
git log --oneline

Step 4: Handle Uncommitted Work During Sync

Objective: Learn to manage uncommitted work when you need to sync with team changes.

Detailed Steps:

  1. Return to feature branch:
git checkout feature/user-dashboard
  1. Create uncommitted work:
echo "/* Dashboard Styles */
.dashboard-container {
    padding: 20px;
    background: #f5f5f5;
}" > styles.css
  1. Check status to see uncommitted changes:
git status

You should see styles.css as an untracked file.

  1. Stash uncommitted work safely:
git stash push -m "WIP: dashboard styling"

  1. Verify stash worked:
git status

The working directory should now be clean.

  1. Get latest changes from main branch:
git fetch origin
git rebase origin/main
  1. If conflicts occur during rebase:
# Edit the conflicted files in VS Code
# After resolving conflicts:
git add .
git rebase --continue
  1. Restore your stashed work:
git stash pop
  1. Commit the stashed work:
git add styles.css
git commit -m "Add dashboard styling"

Phase 3: History Cleaning & Security Remediation

Step 5: Fix Security Issues Professionally

Objective: Discover and resolve security mistakes without creating noise in the commit history.

Detailed Steps:

  1. Identify the security issue in history:
git log --oneline -5

Look for the commit that added the .env file with secrets.

  1. Remove sensitive data from environment file:
echo "# Environment Configuration Template
# Add actual values in deployment environment
API_KEY=your-api-key-here
DB_PASSWORD=your-database-password-here" > .env
  1. Amend the commit to fix the security issue:
git add .env
git commit --amend -m "feat: add environment configuration template"

  1. Verify the fix:
git log --oneline
cat .env

The commit message should be updated and the .env file should no longer contain real secrets.

Step 6: Create Clean, Atomic History

Objective: Transform multiple messy commits into a single, coherent feature commit.

Detailed Steps:

  1. View current branch history:
git log --oneline

Note the commit hashes for the last 3-4 commits.

  1. Start interactive rebase:
git rebase -i HEAD~4
  1. In the interactive rebase editor:
pick abc1234 Add dashboard component
squash def5678 Add environment configuration
squash ghi9012 Implement user data functions
squash jkl3456 Add dashboard styling
  1. After saving, provide comprehensive commit message:
feat: implement user dashboard system

- Add dashboard JavaScript component with core functionality
- Include environment configuration template for secure deployment
- Implement user data management functions
- Add responsive styling for dashboard container

Security: Removed hardcoded credentials in favor of template
Testing: Manual review of dashboard functionality
  1. Verify the clean history:
git log --oneline

You should see one clean commit instead of multiple small ones.


Phase 4: Project Hygiene & Ignoring Files

Step 7: Establish Professional Gitignore

Objective: Prevent future mistakes by properly configuring which files Git should ignore.

Detailed Steps:

  1. Create comprehensive .gitignore file:
cat > .gitignore << 'EOF'
# Environment variables (never commit secrets!)
.env
.env.local
.env.production
*.cfg

# Log files
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Dependency directories
node_modules/
jspm_packages/

# Build outputs
/dist/
/build/
/out/

# IDE and editor files
.vscode/
.idea/
*.swp
*.swo

# OS metadata
.DS_Store
.DS_Store?
._*
.Spotlight-V100
.Trashes
Thumbs.db
EOF
  1. Test the gitignore with files that should be ignored:
touch .env.local debug.log production.cfg
mkdir node_modules dist
touch node_modules/package.json dist/bundle.js
  1. Commit the gitignore:
git add .gitignore
git commit -m "chore: establish comprehensive gitignore rules"
  1. Verify ignored files are properly excluded:
git status

You should only see .gitignore in the changes, not the test files we created.


Phase 5: Code Review & Integration

Step 8: Push and Prepare for Review

Objective: Share your work with the team following best practices.

Detailed Steps:

  1. Push feature branch to remote:
git push -u origin feature/user-dashboard
  1. If history was rewritten during rebase, update safely:
git push --force-with-lease origin feature/user-dashboard

  1. Verify remote branch:
git branch -r

Step 9: Simulate Code Review Process

Objective: Practice the integration workflow used in professional environments.

Detailed Steps:

  1. Switch to main branch for integration:
git checkout main
  1. Pull latest changes from team:
git pull origin main
  1. Merge feature with descriptive message:
git merge --no-ff feature/user-dashboard -m "feat: integrate user dashboard system

- Adds responsive user dashboard component
- Includes secure environment configuration
- Implements user data management functions
- Adds comprehensive styling

Testing: Manual review of dashboard functionality
Security: Environment template prevents credential exposure"

  1. Push the integrated changes:
git push origin main

Phase 6: Emergency Response & Maintenance

Step 10: Handle Critical Production Issue

Objective: Simulate an emergency hotfix scenario that requires immediate attention.

Detailed Steps:

  1. Create hotfix branch from main:
git checkout -b hotfix/welcome-message main
  1. Introduce and discover a critical typo:
echo "Welcoe to Project Storm! We're excited to have you." > welcome.txt
git add welcome.txt
git commit -m "Add welcome message"

  1. Discover and fix the critical typo immediately:
echo "Welcome to Project Storm! We're excited to have you." > welcome.txt
git add welcome.txt
git commit --amend -m "fix: correct critical welcome message typo"
  1. Verify the fix:
cat welcome.txt
git log --oneline

The file should show the correct spelling and history should show one clean commit.

Step 11: Deploy Hotfix and Cleanup

Objective: Complete the emergency fix and maintain repository hygiene.

Detailed Steps:

  1. Integrate hotfix into main branch:
git checkout main
git merge hotfix/welcome-message
  1. Push the hotfix:
git push origin main

  1. Clean up local branches:
git branch -d feature/user-dashboard
git branch -d hotfix/welcome-message
  1. Remove remote feature branch:
git push origin --delete feature/user-dashboard
  1. Verify cleanup:
git branch -a

You should only see main and remote/main branches.


Conclusion

Key Workflows Mastered

1. Complete Feature Development Cycle

  • Proper repository initialization and remote setup

  • Branch isolation for feature work

  • Atomic commit practices with meaningful messages

  • Regular synchronization with main branch

2. Security Incident Response

  • Identification of sensitive data in commits

  • Safe remediation using amend without history pollution

  • Prevention through comprehensive gitignore configuration

  • Template-based approach for configuration files

3. Professional History Management

  • Interactive rebase for clean, logical history

  • Commit squashing for feature cohesion

  • Meaningful commit messages for team clarity

  • Safe history rewriting with force-with-lease

4. Emergency Response Protocol

  • Hotfix branch strategy for critical issues

  • Rapid typo correction with amend

  • Safe integration with main branch

  • Proper branch lifecycle management

5. Repository Maintenance Excellence

  • Systematic branch cleanup post-merge

  • Remote repository synchronization

  • Working directory hygiene practices

  • Comprehensive status verification

Professional Standards Achieved

  • Security First: Never commit credentials, use templates and gitignore

  • Atomic Commits: Single responsibility per commit with clear messages

  • Clean History: Linear, readable history for team collaboration

  • Safe Practices: Force-with-lease instead of dangerous force pushes

  • Branch Hygiene: Proper lifecycle management from creation to deletion

  • Comprehensive Verification: Multiple checkpoints to ensure repository health

This workflow transforms you from someone who knows Git commands to someone who understands Git strategy—the essential mark of a true DevOps professional. The patterns practiced here will enable you to handle any version control challenge with confidence and maintain clean, secure, and collaborative repositories throughout your career.