Mastering Git Town: Tips & Commands for Faster BranchingGit Town is a command-line tool and workflow designed to make branching, syncing, and collaboration in Git faster and less error-prone for teams. It builds on top of Git by adding higher-level commands that encapsulate best practices for feature branches, trunk-based work, and release processes. This article walks through why Git Town can help your team, how it changes common workflows, and practical tips and commands to get the most out of it.
Why use Git Town?
Git Town automates repetitive sequences of Git commands (pull, rebase, merge, delete branches, etc.), reducing human error and saving time. It enforces a consistent workflow so team members follow the same branching rules, which leads to fewer merge conflicts and cleaner history. For teams practicing frequent integration or trunk-based development, Git Town accelerates daily tasks like syncing branches and finishing work.
Key concepts
- Mainline: the primary integration branch (often called main or master). Git Town encourages a clean, up-to-date mainline.
- Persistent branches: long-lived branches (e.g., for teams or components) that you frequently rebase onto mainline.
- Feature branches: short-lived branches created for specific tasks; Git Town provides commands to create, sync, and finish them reliably.
- Ship/Finish: safe ways to merge feature work back into mainline, optionally squashing or preserving history according to your policy.
Installing Git Town
Install via package managers or download binaries. Common options:
- Homebrew (macOS): brew install git-town
- apt (Linux): follow Git Town docs for distribution packages
- Windows: use Scoop or Chocolatey, or download the executable
After installation, run git town configure to set defaults like your main branch name and branch naming conventions.
Basic workflow commands
- git town new
— creates a feature branch from the mainline and makes it your current branch. - git town sync — updates the current branch with changes from the mainline, typically by rebasing onto the latest mainline.
- git town ship (or finish) — integrates your feature branch back into mainline in a safe, automated way and deletes the branch if configured.
- git town hack — starts a local-only branch that won’t be pushed; useful for quick experiments.
- git town prune — removes local branches that have been deleted upstream.
These commands replace multi-step sequences such as: git checkout main; git pull –rebase; git checkout -b feature; git add .; git commit; git checkout main; git pull –rebase; git merge –no-ff feature; git push; git branch -d feature.
Example: Fast feature flow
- git town new feature/ui-improvements
- Work and commit locally.
- git town sync (keeps branch updated with main)
- git town ship (merges into main and deletes branch)
This sequence keeps history linear and reduces merge pain.
Rebasing vs merging with Git Town
Git Town favors rebasing for keeping a linear history when syncing feature branches onto the mainline. Use git town sync to rebase your feature branch onto the latest mainline. When finishing, you can configure whether to merge with a merge commit, fast-forward, or squash. Configure these in git town settings so the team follows a consistent policy.
Tips for teams
- Run git town configure together and agree on main branch name and merge strategy.
- Use persistent branches for areas of the codebase to reduce conflicts across multiple short-lived features.
- Teach team members to run git town sync frequently — it’s cheap and reduces large conflict resolutions.
- Combine with protected mainline branches on your Git hosting (GitHub/GitLab) to enforce code review and CI checks; Git Town handles the local branch hygiene and merging.
Handling conflicts
Conflicts can still occur. Git Town will stop at conflict points during rebase so you can resolve them as usual (git add, git rebase –continue). After resolving conflicts, continue with git town sync or git town ship as needed. For complicated conflicts across many branches, consider temporarily creating an integration branch and using git town hack to experiment.
Advanced commands
- git town set-parent
— make one branch the parent of another (useful for persistent branches). - git town hack — for local experiments that shouldn’t be pushed.
- git town repair — attempt automatic fixes for common repository problems.
- git town ship –no-push — finish locally without pushing, useful for CI or review workflows.
Configuration examples
Set main branch and preferred sync strategy:
git town config set main-branch main git town config set sync-strategy rebase
Configure automatic deletion after ship:
git town config set delete-merged-branches true
Common pitfalls & solutions
- Pitfall: forgetting to sync before starting work. Solution: make git town sync part of your daily routine and pre-commit hook reminders.
- Pitfall: team members using different main branch names. Solution: enforce via git town configure and repository docs.
- Pitfall: conflicts during large rebases. Solution: split large changes into smaller feature branches and sync frequently.
When not to use Git Town
If your team already relies heavily on merge commits and a non-linear history policy, or if you use a Git hosting workflow that enforces a strict branching model incompatible with local rebasing, Git Town’s automation may conflict with your policies. Also, teams unfamiliar with rebasing should get basic Git training first.
Conclusion
Git Town streamlines branching, syncing, and finishing workflows with simple commands that encapsulate Git best practices. By configuring a consistent team workflow, using frequent syncs, and leveraging Git Town’s higher-level operations, teams can reduce merge conflicts and speed up feature delivery.