Git Workflow With Git Town
|Feb 23, 2021||Git Workflow With Git Town|
Painful But Powerful
Let’s get this out of the way.
Git isn’t intuitive.
It has quite a bit of a learning curve.
However, with this flexibility comes great flexibility. This tool has powered so much of modern open-source development.
Optimize for the Pain
To improve the development experience some tools can help provide structure.
This won’t be an attempt to compare every git GUI, or push any specific tooling. It’s more sharing my experience and what I’ve found helps accelerate my usage.
Tools I’ve Relied On
I’m not going to go into full detail on each, but check these out to help expedite your workflow.
The Challenge In Keeping Up To Date With Main
I use what’s normally called
This entails regularly moving commits from branches into the main branch, often rebasing while maintaining it in a functional state.
I’ll create a feature branch, bug fix, or refactor branch and then merge this to
main as soon as functional.
I prefer a rebase approach on my branches, and when many ci/fix type commits, to squash this into a single unit of work as the results of the PR. This can result in “merge hell” as you try rebase on a busy repo.
Enter Git Town
This tool solves so many of the basic workflow issues, that it’s become one of the most impactful tools to my daily work.
git hack feat/new-feature, etc as examples because I’ve run the command
git-town alias truewhich enables the alias configuration for git town, reducing verbosity. Instead of
git town sync, you can run
Example 1: Create a Branch for a New Unit of Work While You Are Already On Another Branch
Normally this would require:
- Stash/Push current work
- Checkout master
- Fetch latest and pull with rebase
- Resolve any conflicts from rebase
- Create the new branch from main
- Switch to the new branch
With Git Town
git hack feat/new-feature
Example 2: Sync Main
The following steps would be performed by:
Example 3: New Branch From Main
Easy to quickly ensure you are up to date with remote and generate a new branch with your current uncommitted changes.
Example 4: Quickly Create a PR While On A Branch for Seperate Set of Changes
This workflow is far too tedious to do without tooling like this.
Let’s say I’m on a branch doing some work, and then I recognize that another bug, doc improvements, or other change unrelated to my current work would be good to submit.
With git town, it’s as simple as:
I can stage individual lines using VSCode for this fix if I want to, and then after committing:
Example 5: Ship It
When not using a PR-driven workflow, such as solo projects, then you can still branch and get your work over to main to keep a cleaner history with:
This command ensures all the sync features are run, while then initiating a squash of your branch, allow you to edit the squash message, rebase merge this onto main, and finally clean-up the stale branch.
Check out the documentation from the creators: Git Town Tutorials
Other Cool Features
- Automatically prune stale branches after PR merge when syncing
- Handles perennial branches if you are using Git Flow methodology.
- Extensible for other git providers.
- Rename a local branch + remote branch in a single command
- Handles a lot of edge cases and failures
When using git, leveraging some tooling like this can accelerate your workflow. I don’t think you need to be an expert in git to use this, as it helps simplify many workflows that are just too tedious to be diligent on when running manually.
You can also do much of this with git aliases, but Git Town has a pretty robust feature-set with a testing framework in place, edge condition handling, and it’s fast. Consider using it you’d like to improve your git workflow while simplifying all the effort to do it right.