A good Git branching workflow keeps a small project understandable without adding ceremony. This guide compares trunk-based development, feature branches, and release branches, then gives you reusable command sequences and checklists for starting work, reviewing changes, resolving conflicts, and recovering from mistakes.
Overview
For a solo developer or small team, the best Git branching workflow is usually the simplest one that protects the main branch and makes unfinished work visible. Branches should have a clear purpose, a short lifetime when possible, and an obvious path to integration.
Most small projects can begin with one of these approaches:
| Workflow | How it works | Good fit | Watch for |
|---|---|---|---|
| Trunk-based development | Developers integrate small changes into main frequently, often through short-lived branches or direct commits where appropriate. | Solo projects and teams that can test changes quickly. | Requires discipline, small changes, and a reliable test process. |
| Feature branches | Each feature, fix, or experiment gets its own branch and is merged into main after review or testing. | Small teams using pull requests or developers working on several tasks. | Long-lived branches can drift and create larger merge conflicts. |
| Release branches | A branch is created to stabilize a planned release while new work continues elsewhere. | Projects with scheduled releases, support branches, or formal stabilization periods. | Extra merges and backports can become confusing for a small codebase. |
A practical default is a protected main branch plus short-lived feature branches. A solo developer may use trunk-based development for tiny changes and create a branch for anything experimental or difficult to undo. Add release branches only when you have a real need to stabilize one version while development continues.
Checklist by scenario
Starting a feature or fix
- Check the current branch and working tree:
git status. - Move to the integration branch:
git switch main. - Update it from the shared repository:
git pull --ff-only origin main. - Create a focused branch:
git switch -c feature/short-description. - Make one coherent change at a time. Keep unrelated formatting or refactoring out of the branch.
- Review the result with
git diff, run the relevant tests, and commit a meaningful unit of work.
Use names that communicate intent, such as fix/login-timeout, feature/search-filter, or chore/update-dependencies. The exact naming convention matters less than using it consistently.
Preparing a branch for review
- Inspect commits and changed files with
git log --onelineandgit diff main...HEAD. - Run tests, linters, formatters, and any local build checks used by the project.
- Update the branch from
mainif it has changed. Choose merge or rebase according to your team convention; do not rewrite commits that others are actively using without agreement. - Push the branch:
git push -u origin feature/short-description. - Open a pull request if your hosting platform and team process use review. Explain what changed, how it was tested, and any known limitations.
Keep a pull request narrow enough that another person can understand its intent. If the change affects an API or database, document the contract and migration steps alongside the code. Related guidance is available in the OpenAPI documentation workflow and database migration checklist.
Merging completed work
- Confirm required checks have passed and requested review comments are resolved.
- Use the merge method your project has agreed on. Avoid changing history merely to make the branch look cleaner.
- After merging, update your local repository:
git switch main, thengit pull --ff-only origin main. - Delete the finished local branch with
git branch -d feature/short-description. - Delete the remote branch when your hosting platform has not already done so:
git push origin --delete feature/short-description.
Resolving a merge conflict
- Pause and identify the operation with
git status. Do not start unrelated work. - Open each conflicted file and decide which lines should remain. Conflict markers look like
<<<<<<<<,=======, and>>>>>>>; remove them after editing. - Run focused tests or inspect the affected behavior.
- Stage resolved files with
git add path/to/file. - Continue the operation with
git merge --continueorgit rebase --continue, depending on what you started. - If the approach is unclear, return safely with
git merge --abortorgit rebase --abort, then ask for context before trying again.
What to double-check
- Branch protection: Decide whether
mainshould require a pull request, passing checks, or approval before merging. Configure only rules your team can consistently maintain. - Testing expectations: Write down the commands that must pass locally and in continuous integration. For Python projects, a test workflow such as pytest can make this repeatable; see the pytest testing guide.
- Secrets: Never commit passwords, tokens, private keys, or local environment files. If a secret was committed, treat it as exposed and follow your provider's rotation process.
- Merge direction: Confirm whether you are merging
maininto your feature branch or your feature branch intomain. Readgit statusbefore executing a command. - Generated files: Check the repository's ignore rules so build output, dependencies, and editor files do not enter a commit accidentally.
- Automation: If a merge triggers deployment or other jobs, verify the workflow file, environment variables, and permissions before merging. The GitHub Actions troubleshooting guide can help when CI fails.
Common mistakes
Working directly on main
Direct commits may be acceptable for a private experiment, but they make review and rollback harder. Use a feature branch for changes that need discussion, testing, or a clear audit trail.
Keeping branches alive too long
A branch that stays open for weeks accumulates differences from main. Break the work into smaller slices, integrate incrementally, or use feature flags when incomplete code must be merged safely.
Using force push casually
Force pushing can remove commits from a shared remote branch. If rewriting your own unpublished branch is necessary, understand whether your team permits it and use the least disruptive option. Never use a destructive command as a substitute for checking the branch and remote first.
Deleting before verifying the merge
Before deleting a branch, confirm the pull request is merged and that the resulting commit exists on main. If a commit is lost locally, use git reflog to locate recent branch and commit positions; create a safety branch before attempting recovery.
Committing unrelated changes together
Unrelated edits make review, rollback, and conflict resolution more difficult. Stage deliberately with git add path/to/file or git add -p, and check git diff --staged before committing.
When to revisit
Review your Git branching workflow at the start of a new project phase, before a planned release, and whenever the team or deployment process changes. It is also worth revisiting after repeated merge conflicts, unclear pull requests, accidental commits, or a growing queue of unfinished branches.
Use this short review checklist:
- Can a new contributor tell which branch is safe to use?
- Can a small change reach
mainwithout unnecessary steps? - Are tests and code review expectations explicit?
- Are abandoned branches and stale pull requests being removed?
- Does the workflow match the current release and deployment process?
Start small: protect main, name branches clearly, keep changes focused, and document the commands your project expects. If the project grows, add release branches or more formal approvals only when they solve a demonstrated problem. For broader project planning, pair this workflow with a practical coding project plan and a repeatable local API testing process such as the one described in the REST API testing guide.