Published: 13 October 2024
Tagged: Git
A familiar situation: someone writes in the team chat โ โI pushed changes, please rebaseโ. You have to stop what youโre doing and run several commands to update. Itโs routine that breaks your focus. I decided to find a solution and discovered there are many options. After researching several, I chose GitTown โ a tool that speeds up routine Git tasks.
Trunk-Based Development
Using trunk-based development means regularly merging changes from feature branches into the main branch, keeping it up to date and working.
For each new feature, fix, or improvement, a separate branch is created and merged into the main branch as soon as the work is done.
I use rebase to keep history clean, and squash many small commits into one (squash commit). This simplifies the integration process and helps avoid conflicts in an actively changing repository.
Thatโs why syncing with the main branch happens quite often, and if you add a stacked branch approach on top of that, it can take a lot of time and become tedious routine.
New feature branch
While in a working branch current-feature, I can run git town hack feat/mob-1-test-fix. This command automates several routine operations: it first syncs the main branch with remote (to avoid future conflicts), then creates a new branch from the updated main and automatically switches to it.
~ on [current-feature] git town hack feat/mob-1-test-fix
[current-feature] git fetch --prune --tags
[current-feature] git checkout develop
[develop] git rebase origin/develop
[develop] git checkout -b feat/mob-1-test-fix
~ on [feat/mob-1-test-fix]Log of the hack command ๐
Quick sync
Working in a feature branch, you need to update the main branch and rebase to integrate the latest changes. The git town sync command automates this process: it updates the main branch and performs a rebase, simplifying synchronization.
~ on [MOB-current-feature] git town sync
[MOB-current-feature] git fetch --prune --tags
[MOB-current-feature] git checkout develop
[develop] git rebase origin/develop
[develop] git checkout MOB-current-feature
[MOB-current-feature] git rebase develop
[MOB-current-feature] git push -u origin MOB-current-feature
~ on [MOB-current-feature]Log of the sync command ๐
Stacked branches
The most convenient command to use is stacked branch. To add a new feature on top of the current branch, simply run append. The branch structure can be viewed with the branch command.
Then, switch to the last branch in the stack and run git town sync. This command syncs all branches sequentially โ starting from the main branch and ending with the current one.
~ on [MOB-current-feature] git town branch
develop
mob-1-current-feature
* mob-2-add-more-uiLog of the branch command ๐