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.
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.
I’m not going to go into full detail on each, but check these out to help expedite your workflow.
I use what’s normally called
trunk-based development. 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.
This tool solves so many of the basic workflow issues, that it’s become one of the most impactful tools to my daily work.
The examples that follow use
git hack feat/new-feature, etc as examples because I’ve run the command
git-town alias true which enables the alias configuration for git town, reducing verbosity. Instead of
git town sync, you can run
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
The following steps would be performed by:
[master] git fetch --prune --tags [master] git add -A [master] git stash [master] git rebase origin/master [master] git push --tags [master] git stash pop
Easy to quickly ensure you are up to date with remote and generate a new branch with your current uncommitted changes.
[master] git fetch --prune --tags [master] git add -A [master] git stash [master] git rebase origin/master [master] git branch feat/demo-feature master [master] git checkout feat/demo-feature [feat/demo-feature] git stash pop
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:
git town hack feat/improve-docs.
This pulls the latest, flips you over to the new branch, and sets you up to commit just the lines or files you need from all the pending changes that still show up. Commit those specific changes, sync, and you’ve now got an upstream branch with minimal effort that is also updated from main.
[feat/demo-feature] git fetch --prune --tags [feat/demo-feature] git add -A [feat/demo-feature] git stash [feat/demo-feature] git checkout master [master] git rebase origin/master [master] git branch feat/demo-feature-2 master [master] git checkout feat/demo-feature-2 [feat/demo-feature-2] git stash pop
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
git town ship.
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
- 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.