PaoloJulian.dev - Article

go to article list

Having trouble updating branches that is dependent to one another? Enter git-branch-updater

Paolo Vincent Julian
Having trouble updating branches that is dependent to one another? Enter git-branch-updater banner

Git Branch Updater - Banner

TLDR; I was tired of typing git switch, git pull, git merge and that shitty repetitive stuff just to update all the dependent branches. I then decided to create a script to ease my git workflow, with just 1 command, you can update and even merge dependent feature branches. e.g. git-branch-updater main/dev/81/82/83/84

Scenario

You have this huge ticket, then you decide to split it into 3 sub-tasks.

  • Main Task (Task List) feat/81/task-list
  • Sub Task (Task Item) feat/81/sub/82/task-item
  • Sub Task (Integrate API) feat/81/sub/83/task-list-integrate-with-api
  • Sub Task (Tests) feat/81/sub/84/task-list-tests

Some of them are now in code review, you are now working on the final sub-task, but you have to change something on the first tasks (task-item) due to something you found out suddenly, or a reviewer requested some changes.

Now, you have to edit that feature-branch, then update everything to the last feature-branch just to get the new changes, this is time consuming as you have to switch branches then pull them one-by-one.

I was frustrated just to type those long branch names, so I created a script.

The Script

Given the multiple dependent branches earlier:

-> dev # Included this to pull latest changes from dev
-> feat/81/task-list
-> feat/81/sub/82/task-item
-> feat/81/sub/83/task-list-integrate-with-api
-> feat/81/sub/84/task-list-tests

Updating feat/81/sub/84/task-list-tests from the latest dev can be tedious. With git-branch-updater, it's a single command:

sh
$ git-branch-updater dev/81/82/83/84

Result

$ git-branch-updater main/dev/81/82/83/84

-- 1. Fetching branches
-- 2. Convert args to full branch names
---- Getting all branch names (git branch -a)
---- Mapping args to full branch names

Is this the correct list of branches?
  -> dev
  -> feat/81/task-list
  -> feat/81/sub/82/task-item
  -> feat/81/sub/83/task-list-integrate-with-api
  -> feat/81/sub/84/task-list-tests
Continue? (y/n): y 
Continuing...

-- 3. Updating branches to latest change
---- Pulling branch: dev
---- Pulling branch: feat/81/task-list
---- Pulling branch: feat/81/sub/82/task-item
---- Pulling branch: feat/81/sub/83/task-list-integrate-with-api
---- Pulling branch: feat/81/sub/84/task-list-tests
-- 4. Merge dependent branches
---- Merging branch: dev --> feat/81/task-list
---- Merging branch: feat/81/task-list --> feat/81/sub/82/task-item
---- Merging branch: feat/81/sub/82/task-item --> feat/81/sub/83/task-list-integrate-with-api
---- Merging branch: feat/81/sub/83/task-list-integrate-with-api --> feat/81/sub/84/task-list-tests
-- 5. Finished%                     

This saved me tons of time when encountering this scenario.

Other Options

  • --no-merge : This only pulls the latest changes into its own feature branch, this will not merge dependent branch

Example: If you just want to update your local branches (main, staging, dev)

sh
$ git-branch-updater main/staging/dev --no-merge

Release: https://github.com/paolojulian/git-branch-updater/releases/tag/v1.0.0

Github: https://github.com/paolojulian/git-branch-updater

TAGS:

#git

#workflow

go to article list