Advanced Git Workflows: Trunk-Based Development and Beyond

In 2026, trunk-based development has become the standard for high-performing teams. Learn the Git workflows that enable continuous delivery and reduce merge conflicts.

Trunk-Based Development

The core idea: everyone commits to a single branch (main/trunk), using short-lived feature branches that last 1-2 days maximum.

# Create a short-lived feature branch
git checkout -b feat/add-search main

# Work, commit frequently
git add -A && git commit -m "feat: add search component"
git add -A && git commit -m "feat: add search API integration"

# Rebase before merging
git fetch origin && git rebase origin/main

# Merge back quickly
git checkout main && git merge feat/add-search
git push origin main
git branch -d feat/add-search

Conventional Commits

# Format: type(scope): description
git commit -m "feat(auth): add OAuth2 login"
git commit -m "fix(api): handle null response"
git commit -m "docs(readme): update installation steps"
git commit -m "perf(db): optimize user query"
git commit -m "refactor(utils): extract validation logic"

Types: feat, fix, docs, style, refactor, perf, test, chore, ci

Interactive Rebase for Clean History

# Squash last 3 commits
git rebase -i HEAD~3

# In the editor:
pick abc1234 feat: add search
squash def5678 fix: search styling
squash ghi9012 test: add search tests

Git Worktrees

# Work on multiple branches simultaneously
git worktree add ../hotfix-branch hotfix/urgent-fix

# Work in the new directory
cd ../hotfix-branch
# Make fixes...

# Clean up
git worktree remove ../hotfix-branch

Useful Git Aliases

# Add to ~/.gitconfig
[alias]
  lg = log --graph --oneline --all --decorate
  st = status -sb
  co = checkout
  cm = commit -m
  undo = reset --soft HEAD~1
  amend = commit --amend --no-edit
  cleanup = "!git branch --merged | grep -v main | xargs -n 1 git branch -d"

Git Hooks with Husky

# package.json
{
  "scripts": {
    "prepare": "husky"
  }
}

# .husky/pre-commit
npx lint-staged

# .husky/commit-msg
npx commitlint --edit $1

GitHub Actions for CI

name: CI
on:
  push:
    branches: [main]
  pull_request:
jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
      - run: npm ci
      - run: npm test
      - run: npm run lint

Conclusion

Trunk-based development with conventional commits, automated CI, and clean Git history is the gold standard. Adopt these practices to ship faster with fewer conflicts.

Comments

Leave a Reply

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

Privacy Policy · Contact · Sitemap

© 7Tech – Programming and Tech Tutorials