DevOps Lesson 3: Git Advanced

⚙️ DevOps CourseLesson 3 of 10 · 30% complete

Beyond basic commits — branching strategies, rebasing, and workflows used by professional teams.

Branching Strategy

# GitFlow: main + develop + feature/* + release/* + hotfix/*
# Trunk-based: everyone pushes to main with feature flags
# GitHub Flow: main + feature branches + PRs (most common)

# Create and switch branch
git checkout -b feature/user-auth
git push -u origin feature/user-auth

# Merge with PR (on GitHub) or locally:
git checkout main
git merge feature/user-auth --no-ff  # preserve merge commit

Rebase & Cherry-pick

# Rebase: replay your commits on top of updated main
git fetch origin
git rebase origin/main       # cleaner history than merge
# Resolve conflicts, then: git rebase --continue

# Interactive rebase: squash, reorder, edit commits
git rebase -i HEAD~5         # reword last 5 commits

# Cherry-pick: apply specific commit from another branch
git cherry-pick abc123       # apply commit abc123 to current branch

.gitignore & Hooks

# .gitignore — never commit these:
node_modules/
.env
dist/
*.log
.DS_Store
coverage/

# Git hooks (in .git/hooks/):
# pre-commit: run linter before each commit
# pre-push: run tests before push
# Use husky npm package to manage hooks:
npm install -D husky
npx husky init
# Edit .husky/pre-commit: npm run lint

🏋️ Practice Task

Practice: create a repo with main + develop branches. Create 3 feature branches, make commits on each, merge all into develop. Practice rebase instead of merge. Use interactive rebase to squash 3 commits into 1. Set up a pre-commit hook that runs ESLint.

💡 Hint: git log –oneline –graph –all to visualize the branch tree.

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *