# The entire workflowgit checkout main
git pull
# make changesgit add .
git commit -m "Add user search feature"git push
When it works:
Solo projects
Small teams with high trust
Continuous deployment
Strong test coverage
The catch: Requires feature flags for incomplete work:
1
2
3
4
5
6
7
8
9
10
# Feature flags for trunk-basedfromconfigimportfeaturesdefget_users():users=fetch_all_users()iffeatures.is_enabled('user_search'):users=apply_search_filter(users)returnusers
One step up: short-lived feature branches with pull requests.
1
2
3
4
5
6
7
8
9
10
11
12
# Start a featuregit checkout main
git pull
git checkout -b feature/user-search
# Work on itgit add .
git commit -m "Add search endpoint"git push -u origin feature/user-search
# Open PR, get review, merge to main# Deploy main automatically
main # Production code, tagged releasesdevelop # Integration branch, next releasefeature/* # New features, branch from developrelease/* # Release prep, branch from develophotfix/* # Emergency fixes, branch from main
# Branch from developgit checkout develop
git checkout -b release/1.2.0
# Bump version, final fixesecho"1.2.0" > VERSION
git commit -am "Bump version to 1.2.0"# Merge to main and taggit checkout main
git merge --no-ff release/1.2.0
git tag -a v1.2.0 -m "Release 1.2.0"git push origin main --tags
# Merge back to developgit checkout develop
git merge --no-ff release/1.2.0
git push
git branch -d release/1.2.0
Hotfix workflow:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# Branch from maingit checkout main
git checkout -b hotfix/security-fix
# Fix the issuegit commit -am "Fix XSS vulnerability"# Merge to maingit checkout main
git merge --no-ff hotfix/security-fix
git tag -a v1.2.1 -m "Hotfix 1.2.1"git push origin main --tags
# Also merge to developgit checkout develop
git merge --no-ff hotfix/security-fix
git push
git checkout main
git merge feature/user-search
# Creates merge commit, preserves branch history
Rebase (linear history):
1
2
3
4
5
git checkout feature/user-search
git rebase main
git checkout main
git merge feature/user-search # Fast-forward# Linear history, as if changes were made sequentially
Squash merge (clean main):
1
2
3
4
git checkout main
git merge --squash feature/user-search
git commit -m "Add user search feature"# All feature commits become one on main
My preference: Squash merge for features, merge commits for releases.
# During rebasegit rebase main
# CONFLICT in file.py# Fix the conflictvim file.py
git add file.py
git rebase --continue
# If it's a mess, abortgit rebase --abort
Preventing conflicts:
1
2
3
4
5
6
7
8
9
10
# Rebase onto main frequentlygit fetch origin
git rebase origin/main
# Before opening PRgit checkout main
git pull
git checkout feature/my-feature
git rebase main
git push --force-with-lease # Safe force push
# GitHub Flow with squash merge# - main is always deployable# - Feature branches are short-lived (<1 week)# - PRs require 1 review# - Squash merge to keep main clean# - Deploy on merge to main
Complexity is earned, not assumed. Start simple.
Got a Git workflow that works? Share it on Twitter.
📬 Get the Newsletter
Weekly insights on DevOps, automation, and CLI mastery. No spam, unsubscribe anytime.