Lightning-Fast Branch Management with Git-town: Say Goodbye to the Manual Command Nightmare

Git tutorial - IT technology blog
Git tutorial - IT technology blog

The nightmare of managing dozens of Git branches every day

Working in a team of 8 with daily releases, I used to get tired of constantly typing Git commands. Every morning, the process repeated like clockwork: git checkout main, git pull, return to the feature branch, and then git merge main. Repeating this cycle 10 times a day for 3-4 different tasks was common.

The hardest part is when the work is done. You have to push code, create a PR, wait for the merge, and then manually delete branches both locally and remotely. If you forget just one step, your computer will be cluttered with “stale branches” from months ago. In a large project environment, a second of carelessness while typing commands can easily lead to merging old code, causing commit history conflicts for the entire team.

Why does vanilla Git consume so much of our time?

In reality, Git isn’t bad. It is a low-level tool that provides you with discrete building blocks like checkout, merge, or rebase. However, it lacks a complete workflow framework to connect those blocks together.

Most developers waste time on repetitive tasks:

  • Updating the latest code from main before starting a new feature.
  • Continuously syncing feature branches to avoid “massive” conflicts at the end.
  • Cleaning up remnants after successfully shipping code.

Doing it manually is highly error-prone. I once saw a junior developer forget to git pull before creating a branch. As a result, they coded on an outdated foundation from the previous week. By the time it was merged into main, there were so many conflicts that the team spent the entire afternoon resolving them.

Common “half-baked” solutions

Before discovering Git-town, my team tried various methods, but they all had loopholes:

  1. Traditional Git Flow: Too cumbersome with dozens of branch types like develop, release, and hotfix. For web projects needing continuous deployment, Git Flow is like wearing heavy iron armor just to go for a jog.
  2. Custom Shell Scripts: I used to write .sh files to automate pulling and deleting branches. But these scripts quickly became obsolete when encountering conflicts or when the team renamed the main branch from master to main.
  3. Using Aliases: This helps type faster but doesn’t solve the underlying workflow logic.

All of them lack the intelligence to understand the current state of the workflow and automatically handle emerging situations.

Git-town: A Smart Abstraction Layer for Git

After 6 months of practical application, I can affirm that Git-town elevates the Git experience to a new level. It doesn’t replace Git but sits on top of it, executing complex command sequences for you.

Installation and configuration in 30 seconds

If you are on macOS, you only need a single command:

brew install git-town

Next, navigate into your project and run the configuration:

git town config

Git-town will ask you which is the main branch and which are perennial branches (staging, production). You only need to set this up once per project.

4 Git-town commands to “hack” your productivity

Instead of remembering dozens of commands, I only use these 4 core commands to handle 90% of my daily work:

1. Create a new branch: git town hack

Instead of typing 3 commands: checkout main, pull, checkout -b, you just need:

git town hack feature-xyz

This command automatically switches to main, pulls the latest code, creates a new branch, and sets up tracking for you.

2. Sync code: git town sync

This is my favorite command. When you want to pull new code from main into the feature branch you’re working on:

git town sync

It automatically pulls main code, merges it into the current branch, and pushes it to the remote. If there is a conflict, it stops and waits for you to fix it before continuing the automated process.

3. Ship code cleanly: git town ship

Once the PR is approved, don’t delete the branch manually. Run:

git town ship

Git-town will check the merge status, squash commits if necessary, push to main, and wipe the branch from both your machine and the server. Everything is tidy in an instant.

4. Kill a faulty branch: git town kill

If a feature you are working on is canceled, this command cleans up all traces of that branch across the system, leaving no junk behind.

Real-world results after 6 months

Since using Git-town, the number of conflicts in my team has decreased significantly. Because git town sync is so convenient, everyone pulls new code much more frequently. This habit helps detect conflicts early instead of letting them pile up until the end of the sprint.

Notably, Git-town handles Stacked Changes exceptionally well. If you have branch B created from branch A, when syncing branch B, Git-town will automatically pull changes from Main -> A -> B. This is a difficult technique that even veteran developers can easily get wrong when doing it manually.

A few small notes from personal experience:

  • Start using it individually first. When colleagues see you working fast and cleanly, they will naturally come to you to learn.
  • Always run git status to ensure no files are partially edited before syncing.
  • If you hit a conflict, don’t panic. Just fix it and run git town continue, and everything will run smoothly again.

Using Git-town doesn’t just speed up command typing. It frees your mind from trivial tasks so you can focus entirely on writing code. If you’re tired of branch management, try installing it today. You won’t want to go back to the old way.

Share: