DEV Community

Cover image for Smart Branch Naming for GitKraken (and Any Git Workflow)
Rastislav ₡ORE
Rastislav ₡ORE

Posted on

Smart Branch Naming for GitKraken (and Any Git Workflow)

One tiny thing that kept annoying me every single day:

Creating sequential Git branches manually.

I often work with branch names like:

feat/toolname-01
feat/toolname-02
feat/toolname-03
Enter fullscreen mode Exit fullscreen mode

And after a few days of development, I found myself constantly doing this mental loop:

"Wait… was the last branch -07 or -08?"

Not exactly a huge problem 😄
But enough friction to become annoying when repeated dozens of times per week.

So I made a tiny helper script that automatically creates the next branch name based on my latest work.

Now I just run:

git smart-branch
Enter fullscreen mode Exit fullscreen mode

and it instantly creates:

feat/toolname-28
Enter fullscreen mode Exit fullscreen mode

✨ No typing
✨ No counting
✨ No context switching

🧠 The Idea

The script is intentionally simple.

It:

  1. Scans local branches
  2. Sorts them by latest commit date
  3. Finds the newest branch matching:
something/something-01
Enter fullscreen mode Exit fullscreen mode
  1. Increments the number
  2. Creates the next branch automatically

Example:

feat/toolname-27
→ feat/toolname-28
Enter fullscreen mode Exit fullscreen mode

That’s it.

Tiny automation. Surprisingly satisfying.

💻 The Script

Full gist here:

GitHub Gist

⚙️ Installation

1. Save the script

I saved mine as:

~/bin/git-smart-branch
Enter fullscreen mode Exit fullscreen mode

Then make it executable:

chmod +x ~/bin/git-smart-branch
Enter fullscreen mode Exit fullscreen mode

2. Add Git alias

Open your:

~/.gitconfig
Enter fullscreen mode Exit fullscreen mode

and add:

[alias]
smart-branch = "!bash ~/bin/git-smart-branch"
Enter fullscreen mode Exit fullscreen mode

3. Use it 🎉

Inside any Git repository:

git smart-branch
Enter fullscreen mode Exit fullscreen mode

Example output:

Latest branch: feat/toolname-27
Creating: feat/toolname-28
Done.
Enter fullscreen mode Exit fullscreen mode

🐙 GitKraken Integration

Originally I wanted this directly inside GitKraken’s branch UI.

Unfortunately GitKraken currently doesn’t support custom branch naming hooks/plugins.

But this still works perfectly through:

  • GitKraken integrated terminal
  • VSCode terminal
  • Warp
  • iTerm
  • basically any shell

So now my flow inside GitKraken is simply:

git smart-branch
Enter fullscreen mode Exit fullscreen mode

and I’m done.

Honestly… it’s faster than opening the branch modal 😄

🤔 Why Sorting by Commit Date Matters

My first attempt sorted branches alphabetically.

Bad idea.

Because branches like:

feat/payment-03
Enter fullscreen mode Exit fullscreen mode

could accidentally become the “latest” branch even when unrelated.

The final version sorts using:

--sort=-committerdate
Enter fullscreen mode Exit fullscreen mode

which reflects actual recent development activity.

That tiny detail made the script feel much smarter.

🔮 Possible Future Improvements

A few ideas I might add later:

  • interactive rename/edit
  • multiple independent sequences
  • Jira ticket support
  • fuzzy matching
  • branch templates
  • semantic prefixes (feat/, fix/, release/)
  • automatic cleanup of old sequences

But honestly…

the current version already solves 95% of the annoyance.

✨ Final Thoughts

This is one of those micro-automations that takes maybe 10 minutes to build…

…but saves tiny bits of mental energy every single day.

And those tiny frictions add up.

Sometimes developer productivity isn’t about giant frameworks or AI tooling.

Sometimes it’s just:

“I don’t want to manually type -28 anymore.”

rubic

Top comments (0)