Created
May 8, 2023 02:41
-
-
Save usmanity/a6864ea83f3ec85fdc643d7e323c7804 to your computer and use it in GitHub Desktop.
creates a git branch like: `username/year/branch-name` where branch can be passed a space separated branch name
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function branch() { | |
local branch_name | |
if [[ $# -eq 0 ]]; then | |
echo "Usage: branch <name>" | |
return 1 | |
fi | |
if [[ $1 =~ [^a-zA-Z0-9._-] ]]; then | |
echo "Invalid branch name: $1" | |
return 1 | |
fi | |
branch_name="$(id -un)/$(date +%Y)/${*:1}" | |
branch_name=${branch_name// /-} # Replace spaces with dashes | |
if git rev-parse --verify "$branch_name" >/dev/null 2>&1; then | |
echo "Branch '$branch_name' already exists" | |
return 1 | |
fi | |
git checkout -b "$branch_name" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment