Skill v1.0.0
currentAutomated scan100/100name: git-workflow description: Implement Git branching strategies, PR workflows, and release management patterns. category: devops risk: critical source: https://github.com/BagelHole/DevOps-Security-Agent-Skills source_repo: BagelHole/DevOps-Security-Agent-Skills source_type: community date_added: '2026-09-20' license: MIT license_source: https://github.com/BagelHole/DevOps-Security-Agent-Skills/blob/main/LICENSE compatibility: Requires the relevant platform CLIs (kubectl, helm, terraform, git, CI runners) and authorized access to the target environment. Docs-only; helper scripts and templates not bundled. metadata: author: devops-skills version: '1.0'
Git Workflow
Implement effective branching strategies and pull request workflows for team collaboration.
When to Use This Skill
Use this skill when:
- Establishing team Git workflows
- Implementing branching strategies
- Configuring pull request processes
- Setting up release management
- Improving code review practices
Prerequisites
- Git installed
- Repository hosting (GitHub, GitLab, Bitbucket)
- Basic Git knowledge
Repository instructions and branch protection take precedence over every generic example here. Rebase/reset/force-push only within authorized topic history; preserve dirty work, never rewrite shared history silently, and use repository release scripts when required. Stage explicit reviewed paths rather than unrelated files.
Branching Strategies
Trunk-Based Development
Best for: Continuous deployment, small teams, mature CI/CD
main ─────●─────●─────●─────●─────●─────●─────●│ │ │ │ │ │└─● └─● └─● └─● └─● └─●feature branches (short-lived)
# Create short-lived feature branchgit checkout maingit pull origin maingit checkout -b feature/add-login# Work and commit frequentlygit add .git commit -m "feat: add login form"# Keep branch updatedgit fetch origingit rebase origin/main# Publish the topic branch and open a pull requestgit push -u origin feature/add-login# Merge only through the repository-required protected review/check workflow.# Delete the topic branch after the remote merge is confirmed.
GitHub Flow
Best for: Continuous delivery, web applications
main ─────●─────●───────────●─────────────●─────●│ ↑ ↑ ↑└───●───●───┘ │ │feature/login │ ││ │└───●───●───●───●───────┘ │feature/dashboard ││└───●─────────────────────────┘hotfix/security-patch
# Create feature branch from maingit checkout maingit pull origin maingit checkout -b feature/user-dashboard# Push and create PRgit push -u origin feature/user-dashboard# After review, merge via PR (squash recommended)# Delete branch after merge
GitFlow
Best for: Scheduled releases, versioned products
main ────────●────────────────●──────────────●↑ ↑ ↑release ────────┼────●───●──────┼──────────────┼│ │ │ │ │develop ───●────●────┼───●──●───●───●───●───●──┼│ │ │ │ │ │feature ───┴─────────┘ │ │ │ ││ │ │ │hotfix ────────────────────┴───────┼───┼──────┘│ │feature ────────────────────────────┴───┘
# Initialize GitFlowgit flow init# Start featuregit flow feature start user-auth# Finish feature (merges to develop)git flow feature finish user-auth# Start releasegit flow release start 1.0.0# Finish release (merges to main and develop)git flow release finish 1.0.0# Hotfixgit flow hotfix start security-fixgit flow hotfix finish security-fix
Commit Conventions
Conventional Commits
<type>(<scope>): <description>[optional body][optional footer(s)]
Types:
feat: New featurefix: Bug fixdocs: Documentationstyle: Formattingrefactor: Code restructuringtest: Adding testschore: Maintenance
Examples:
git commit -m "feat(auth): add OAuth2 login support"git commit -m "fix(api): handle null response from payment service"git commit -m "docs: update API documentation for v2 endpoints"git commit -m "refactor(db): optimize user query performance"# Breaking changegit commit -m "feat(api)!: change response format for user endpointBREAKING CHANGE: The user endpoint now returns an object instead of array"
Commit Message Template
# Create template file ~/.gitmessage# Subject line (50 chars max)# Body (72 chars per line max)# - What changed# - Why it changed# - Any side effects# Footer# Fixes #123# Co-authored-by: Name <email># Configure Git to use templategit config --global commit.template ~/.gitmessage
Pull Request Workflow
PR Template
<!-- .github/pull_request_template.md -->## DescriptionBrief description of changes## Type of Change-[ ] Bug fix (non-breaking change)-[ ] New feature (non-breaking change)-[ ] Breaking change-[ ] Documentation update## Testing-[ ] Unit tests added/updated-[ ] Integration tests added/updated-[ ] Manual testing performed## Checklist-[ ] Code follows project style guidelines-[ ] Self-review performed-[ ] Documentation updated-[ ] No new warnings introduced## Related IssuesCloses ### Screenshots (if applicable)
Branch Protection Rules
# GitHub branch protectionbranch_protection:branch: mainrequired_pull_request_reviews:required_approving_review_count: 1dismiss_stale_reviews: truerequire_code_owner_reviews: truerequired_status_checks:strict: truecontexts:- "ci/tests"- "ci/lint"restrictions:users: []teams: ["maintainers"]enforce_admins: truerequired_linear_history: trueallow_force_pushes: falseallow_deletions: false
Code Owners
# .github/CODEOWNERS# Default owners* @team-leads# Frontend code/src/frontend/ @frontend-team*.tsx @frontend-team*.css @frontend-team# Backend code/src/api/ @backend-team/src/services/ @backend-team# Infrastructure/terraform/ @platform-team/k8s/ @platform-teamDockerfile @platform-team# Documentation/docs/ @tech-writers*.md @tech-writers
Git Hooks
Pre-commit Hook
#!/bin/sh# .git/hooks/pre-commit# Run lintingnpm run lintif [ $? -ne 0 ]; thenecho "Linting failed. Fix errors before committing."exit 1fi# Run testsnpm run test:unitif [ $? -ne 0 ]; thenecho "Tests failed. Fix tests before committing."exit 1fi# Check for debug statementsif grep -r "console.log\|debugger\|binding.pry" --include="*.js" --include="*.ts" --include="*.rb" src/; thenecho "Remove debug statements before committing."exit 1fi
Using Husky
// package.json{"husky": {"hooks": {"pre-commit": "lint-staged","commit-msg": "commitlint -E HUSKY_GIT_PARAMS"}},"lint-staged": {"*.{js,ts,tsx}": ["eslint --fix", "prettier --write"],"*.{css,scss}": ["prettier --write"]}}
Commitlint Configuration
// commitlint.config.jsmodule.exports = {extends: ['@commitlint/config-conventional'],rules: {'type-enum': [2,'always',['feat', 'fix', 'docs', 'style', 'refactor', 'test', 'chore', 'revert']],'subject-max-length': [2, 'always', 72],'body-max-line-length': [2, 'always', 100]}};
Release Workflow
Automated Release with Tags
# Create annotated taggit tag -a v1.0.0 -m "Release version 1.0.0"# Push taggit push origin v1.0.0# Create release from tag (GitHub CLI)gh release create v1.0.0 \--title "Release 1.0.0" \--notes "Release notes here" \--target main
Changelog Generation
# Using conventional-changelognpx conventional-changelog -p angular -i CHANGELOG.md -s# Using git-cliffgit cliff -o CHANGELOG.md
Common Git Operations
Rebase vs Merge
# Rebase (clean history)git checkout feature/my-featuregit rebase maingit push --force-with-lease# Merge (preserve history)git checkout maingit merge feature/my-feature# Squash merge (single commit)git merge --squash feature/my-featuregit commit -m "feat: add feature X"
Cherry Pick
# Apply specific commit to current branchgit cherry-pick abc123# Cherry pick rangegit cherry-pick abc123..def456# Cherry pick without committinggit cherry-pick -n abc123
Interactive Rebase
# Clean up last 3 commitsgit rebase -i HEAD~3# In editor:# pick abc123 First commit# squash def456 Second commit# reword ghi789 Third commit
Common Issues
Issue: Merge Conflicts
Problem: Conflicts when merging branches Solution: Rebase frequently, communicate with team, use smaller PRs
Issue: Diverged Branches
Problem: Local branch far behind remote Solution: git pull --rebase or git fetch && git rebase origin/main
Issue: Accidental Commit to Wrong Branch
Problem: Committed to main instead of feature Solution: git reset HEAD~1, checkout correct branch, recommit
Best Practices
- Keep branches short-lived (< 1 week)
- Write meaningful commit messages
- Use PR templates consistently
- Require code reviews
- Protect main/master branch
- Automate checks with CI
- Squash merge for clean history
- Delete branches after merge
Related Skills
- semantic-versioning (
semantic-versioning) - Version management - github-actions (
github-actions) - CI/CD automation - feature-flags (
feature-flags) - Feature management
Limitations
- Guidance executes against real environments: confirm target, blast radius, and rollback plan before applying anything.
- Never deploy to production without explicit approval. Docs-only import: upstream scripts and templates not bundled.
Example
git status && git diff --statkubectl diff -f manifest.yaml
Adapted from BagelHole/DevOps-Security-Agent-Skills (MIT); frontmatter, When to Use/Limitations, and safety boundaries added for upstream compliance. Docs-only import: helper scripts and templates not bundled.