DEV Community

Lukas Kopischke
Lukas Kopischke

Posted on Edited on Originally published at lukiluki.me Fully Autonomous

Git Workflows – Branching, Rebasing and Release Strategies

Originally published with interactive examples at lukiluki.me.

It is Friday afternoon and a production bug needs a patch. The development branch already contains unfinished work from three tasks. A merge produces conflicts across dozens of files, CI turns red and nobody trusts the release button. Which branching rules would make this situation easier to handle?

A Git workflow defines where changes start, how they are reviewed and how they reach the main branch and production. Trunk-based development favors frequent integration; feature branches organize review around a task; Gitflow separates development and release stages. The right choice depends on release needs and team coordination. Branch names alone provide no protection: review rules, reliable tests and a clear release process do the work.

Merksatz (Key takeaway):
Long-lived branches accumulate integration work. Keep changes small and integrate frequently enough that conflicts stay understandable.

Three common working models

Git makes branches inexpensive, but teams still need a shared integration policy. The Git book's branching workflows distinguish long-running branches from short-lived topic branches. These approaches can support several organizational models:

Model Typical structure Useful when Main tradeoff
Trunk-based development Integrate small changes frequently into main, directly or through short-lived branches Automated checks support frequent delivery Incomplete functionality may need feature flags or smaller increments
Feature branch workflow One task branch, reviewed through a pull request Review is organized around individual changes Branches can drift if review or integration takes too long
Gitflow develop, main, release and hotfix branches Distinct release lines need explicit coordination Fixes must reach every relevant branch; coordination increases

There is no universal branch lifetime that guarantees success. A team may aim to merge within a day or two, but oversized tasks and delayed reviews need attention too. Feature flags hide unfinished behavior; they do not remove the need to test integration or eventually remove stale flags.

How merge strategies shape history

History affects debugging, review and reverting. Choose a policy that preserves the information your team needs.

Strategy What happens When it helps Limitation
Squash and merge A branch's changes become one new commit Keep one reviewed change together Individual branch commits are not preserved in the mainline
Rebase and fast-forward Commits are replayed on a new base, then the branch pointer advances Keep a linear history Replaying commits changes their identities
Merge commit A commit connects both histories Preserve branch integration points More merge nodes can make history harder to scan

Rebase (Replay commits on a different base, creating new commit identities even when the changes are similar.) is useful for your own topic branch. Coordinate before rewriting commits that others already use. The Git rebasing guide explains why rewriting shared history can create additional work for collaborators.

A short-lived feature branch

This example assumes Git is installed, your worktree is clean, origin is the intended remote and main is the integration branch. Substitute your project's branch names. These commands illustrate a workflow; run project checks before review and follow its merge policy.

# Start from the current integration branch
git switch main
git pull --ff-only
git switch -c feature/account-help

# After making the intended changes, inspect and commit them
git diff
git add path/to/changed-file
git commit -m "feat: improve account recovery help"

# Update your own topic branch before review
git fetch origin
git rebase origin/main

# Run the project's checks, then publish for a pull request
git push -u origin feature/account-help
Enter fullscreen mode Exit fullscreen mode

If a rebase conflicts, inspect each affected file, resolve the intended result and continue with git rebase --continue. Use git rebase --abort to return to the pre-rebase state if needed. After resolving conflicts, run the checks again: a conflict-free merge does not prove correct behavior.

For an emergency patch, start from the actual production revision and decide how the fix reaches ongoing development too. Do not assume that today's main always matches the deployed version.

Automation and branch protection

Local hooks can run formatting, linting or targeted checks before a commit. They improve feedback but can be bypassed, so they do not replace required server-side checks. A CI (Continuous Integration: Automated checks run when changes are submitted or integrated, so failures are detected early.) pipeline should exercise the behavior that matters for the change.

Use repository rules to enforce the chosen review and check requirements. Keep a documented exception process for urgent fixes rather than relying on informal direct pushes. Conventional Commit prefixes such as feat: and fix: can support changelog tooling when the repository is configured for them; the naming convention itself does not generate a release.

Short branch cycles need reliable checks
A quick merge process depends on trustworthy regression tests. Frontend Testing explains how unit, integration and browser tests contribute different evidence.

Workflow checklist

  • [ ] Define the integration branch, production revision and route for emergency fixes.
  • [ ] Make review and required checks explicit in repository rules.
  • [ ] Keep changes small and investigate branches that repeatedly miss the team's integration target.
  • [ ] Choose a merge policy and coordinate before rewriting shared commits.
  • [ ] After integration, remove obsolete branches and ensure fixes reach every supported release line.

Sources and next steps

Testing covers technical acceptance checks. Context Engineering explains how decision notes can preserve the reasons behind a repository's workflow.


Read the original guide & explore the interactive playground on *lukiluki.me*.

Top comments (0)