Branching Strategy
Trunk-Based Development
Best for teams with CI/CD. Everyone works on short-lived branches off main:
git checkout -b fix/broken-deploy
# Make changes, push, create PR
git push origin fix/broken-deploy
# After review, squash merge to mainRules: - Branches live less than 24 hours - Every merge triggers CI/CD - Feature flags hide incomplete work
GitFlow
For projects with scheduled releases:
# Feature branch
git checkout -b feature/new-api develop
# Release branch
git checkout -b release/1.2.0 develop
# Hotfix
git checkout -b hotfix/security-patch mainRebase vs Merge
# Merge — preserves history, creates merge commit
git checkout main
git merge feature-branch
# Rebase — linear history, cleaner log
git checkout feature-branch
git rebase main
git checkout main
git merge feature-branch # Fast-forwardUse rebase for feature branches before merging. Use merge for shared branches (main, develop).
Interactive Rebase
Clean up commits before PR:
git rebase -i HEAD~3pick abc1234 Add initial config
squash def5678 Fix typo in config
squash ghi9012 Add missing fieldResult: three commits become one clean commit.
Master this topic with hands-on labs
Go beyond reading — build real projects in sandboxed environments with expert video guidance.
Browse Courses →Cherry-Pick
Apply a specific commit to another branch:
# Hotfix: apply one commit from develop to main
git checkout main
git cherry-pick abc1234
# Cherry-pick without committing (stage only)
git cherry-pick --no-commit abc1234Bisect
Find which commit introduced a bug:
git bisect start
git bisect bad # Current commit is broken
git bisect good v1.0.0 # This tag was working
# Git checks out a middle commit — test it
# Then mark it:
git bisect good # or git bisect bad
# Repeat until Git finds the culprit
git bisect reset # Return to original branchStash
Save uncommitted work temporarily:
git stash
git stash list
git stash pop # Apply and remove
git stash apply # Apply and keep
git stash drop # Remove without applyingGet weekly IT automation tips
Docker, Ansible, Terraform, MLOps — curated insights delivered to your inbox. No spam.
Subscribe Free →Undo Mistakes
# Undo last commit (keep changes staged)
git reset --soft HEAD~1
# Undo last commit (keep changes unstaged)
git reset --mixed HEAD~1
# Undo last commit (discard changes)
git reset --hard HEAD~1
# Undo a pushed commit (creates new commit)
git revert abc1234
# Recover deleted branch
git reflog
git checkout -b recovered abc1234Hooks for CI/CD
Pre-commit hook — lint before committing:
cat > .git/hooks/pre-commit << 'EOF'
#!/bin/sh
terraform fmt -check
if [ $? -ne 0 ]; then
echo "Run 'terraform fmt' before committing"
exit 1
fi
EOF
chmod +x .git/hooks/pre-commitUse with Husky for team-wide hooks:
{
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
}
}.gitignore for DevOps
# Terraform
.terraform/
*.tfstate
*.tfstate.backup
*.tfplan
# Ansible
*.retry
inventory/*.cache
# Docker
docker-compose.override.yml
# Secrets
.env
*.pem
*.key
vault_pass.txtRelated Posts
- Terraform CI/CD Pipelines for IaC automation - GitHub Actions CI/CD for Terraform for GitHub-specific workflows - Infrastructure as Code Explained for IaC fundamentals -e ---
Ready to go deeper? Explore our hands-on DevOps courses — practical labs covering Docker, Ansible, Terraform, and more.
Ready to learn by doing?
Stop reading tutorials — start building. Expert video courses with hands-on labs in real sandboxed environments.
Related Articles
Git Branching Strategy for Teams
Choose the right Git branching strategy. Compare GitFlow, GitHub Flow, and trunk-based development for different team sizes and needs.
Git Rebase vs Merge Explained
Git rebase vs merge with practical examples. When to use each, interactive rebase workflows, squash commits, and team conventions.
Environment Variables Best Practices
Handle environment variables correctly. Dotenv files, Docker secrets, Kubernetes ConfigMaps, twelve-factor methodology, and security pitfalls.
GitHub Actions CI/CD Advanced Guide
Advanced GitHub Actions for CI/CD. Matrix builds, reusable workflows, dependency caching, artifacts, environments, and self-hosted runners.
GitHub Actions CI/CD for Terraform
Automate Terraform with GitHub Actions. Plan on PR, apply on merge, remote state locking, and secure secrets for IaC pipelines.
GitOps with ArgoCD Beginner Guide
Get started with GitOps using ArgoCD on Kubernetes. Install ArgoCD, create applications, configure sync, and automate deployments.
Explore topics
Browse more articles on the topics covered here.