Aug 19, 2024snippet

Never think about branch names again

a bash script for generating branch names

I recommend swapping out `max` to basically anything else.

#!/bin/bash

# Get the current month and day
month=$(date +%m)
day=$(date +%d)

# Prefix the branch name with max/{month}-{day}
branch_name="max/$month-$day-$1"

# Checkout the branch
git checkout -b "$branch_name"
#!/bin/bash

# Get the current month and day
month=$(date +%m)
day=$(date +%d)

# Prefix the branch name with max/{month}-{day}
branch_name="max/$month-$day-$1"

# Checkout the branch
git checkout -b "$branch_name"

To use on macOS/linux, you can paste the above into a file in `/usr/local/bin` and make it executable with `chmod +x /usr/local/bin/gcb`.

I also recommend setting your git settings to sort branches by `committerdate` so that you can easily find the branch you worked on most recently:

git config --global branch.sort committerdate
git config --global branch.sort committerdate

This does work with the default alphabetical sorting, but this works better if you work on features over long periods of time.