If you’re not using
git as your source controller, you’re missing out.
” Git is a free and open source distributed version control system designed to handle everything from small to very large projects with speed and efficiency.
I have been using it for several years now and always seem to learn new things about it. I have been familiar with its concept of “aliases”, but I’ve never actually taken the time to use them. As part of the workflow for the project I’m on, I end-up with a lot of feature branches left to rot in my fork — they sit there after they have been pulled into
master via a
pull request and corresponding
After a while, I decide it’s time to do some housekeeping — and delete the older branches. I usually find myself googling “git delete remote branch“, (since I can never remember the command). Sometimes I even forget what the command is to delete a local branch too. With
git aliases though we can combine both of these actions into a simplified command that is easy to remember.
Navigate to wherever your global
.gitconfig resides on your computer — for example on my Windows box it’s here
C:\Users\DavidPine\.gitconfig. Open the file in your favorite text editor. We are looking for an
[alias] block, if one does not exist let’s create one at the bottom of the file. Under this block you can create multiple aliases where the left operand is the alias name followed by an
= sign signifying that the right operand is the command.
With the alias above, you can now invoke commands like,
git del myFeatureBranch. This will delete the remote branch first and then the local branch. The nice thing about the “&&” syntax is that command after each double ampersand will only execute if the command in front succeeded. I simply have a few echos and then the core
git commands that I always forget. The
$1 is the placeholder for the variable, in my case the “myFeatureBranch” that is being targeted for deletion.
DISCLAIMER: Do not delete a branch that you currently have checked out, or that has a pending pull request, or has commits that haven’t been synced — in other words, use common sense.
For more on
git aliases visit here. Enjoy!