DEV Community

Kahlil Lechelt
Kahlil Lechelt

Posted on • Originally published at kahlillechelt.com on

belly: Improving Git's Command Line User Experience

My preferred way to use Git is on the command line. I have a set of Git command sequences that I use all the time and that I know by heart but are a nuisance to type out every time and a set of command sequences that I need regularly but have to look up all the time. In order to improve my personal Git user experience I created belly.

belly is a cli-tool that provides a better user experience for some common Git command sequences:

Commit & Push

When working on a personal project or on a feature branch within GitHub Flow, I do this all the time:

git commit -m "my commit message"
git push
Enter fullscreen mode Exit fullscreen mode

That’s a lot of typing for something I do tens of times a day.

belly combines this into one command:

belly c my commit message
Enter fullscreen mode Exit fullscreen mode

Tip: instead of typing belly you can just type b.

Git Checkout Branch Or Create And Checkout

I create branches for features, bug fixes and hot fixes all the times. I also often have to switch between branches.

belly combines switching and creating-and-switching into one command. So instead of:

git checkout my-branch
Enter fullscreen mode Exit fullscreen mode

or

git checkout -b my-branch
Enter fullscreen mode Exit fullscreen mode

I can just do:

belly s my-branch
Enter fullscreen mode Exit fullscreen mode

belly will switch to my-branch if it exists and it will create-and-switch tomy-branch if it doesn’t exist yet.

Set And Delete Tags Locally And On Remote

When you set a version tag you typically want it set in the local and the remote repository. belly allows you to do that with:

belly t v1.0.0
Enter fullscreen mode Exit fullscreen mode

belly can also delete those tags for you:

belly t v1.0.0 -d
Enter fullscreen mode Exit fullscreen mode

Rename A Branch Locally And Remote

This is one of those Git commands I always have to look up. How do I rename a branch again and why is the command to rename it on the server so different?

Anyway, no need to break out Google for that anymore. Just:

belly n my-new-branch-name
Enter fullscreen mode Exit fullscreen mode

and it will rename your local branch as well as the corresponding remote branch for you.

Easy Squashing

There are a couple ways to squash your feature branch commits. If you want to squash everything down to master and add a commit message you can use belly’sq command:

belly q my commit message
Enter fullscreen mode Exit fullscreen mode

Force-Push The Right Way

When you work with rebasing and squashing in order to keep your Git history legible you have to force-push in your feature branches regularly. Rather than using --force-push it is recommended to use --force-push-with-lease which is an awkwardly named flag that does not allow you to force-push if the remote branch has been updated by somebody else. This should be the default.

With belly you can use:

belly p
Enter fullscreen mode Exit fullscreen mode

To force-push-with-lease your current branch state.

If you think any of these convenience methods would be useful to you, feel free to get belly. PRs are welcome, if discussed previously in an issue.

I will be improving belly over time and add more features if I think it would be useful.

Top comments (0)