Last active
July 27, 2023 13:44
-
-
Save timm-oh/7cf314af81d279ba0be448d5cc81603a to your computer and use it in GitHub Desktop.
Creates git branching name according to a specific format
This file contains 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
# All other config | |
# Usage | |
# $ git:(main) new-task "Setup dockerfile for development" | |
# $ git:(tim.mccarthy/setup-dockerfile-for-development) | |
function new-task () { | |
main_branch=$(git symbolic-ref refs/remotes/origin/HEAD | sed 's@^refs/remotes/origin/@@') | |
username=$(git config user.name | tr '[:blank:]' '.') | |
branch_detail=$(echo $1 | sed 's/[^[:blank:][:alnum:]-]//g' | tr '[:blank:]' '-') | |
branch_name=$(echo "$username/$branch_detail" | tr '[:upper:]' '[:lower:]') | |
git checkout $main_branch | |
git pull origin $main_branch | |
git checkout -b "$branch_name" | |
} | |
function rebase () { | |
main_branch=$(git symbolic-ref refs/remotes/origin/HEAD | sed 's@^refs/remotes/origin/@@') | |
current_branch=$(git rev-parse --abbrev-ref HEAD) | |
if [[ "$main_branch" == "$current_branch" ]]; then | |
git pull origin $main_branch | |
echo "Git pulled instead of rebasing" | |
else | |
git checkout $main_branch | |
git pull origin $main_branch | |
git checkout $current_branch | |
git rebase $main_branch | |
fi | |
} | |
function clear-merged() { | |
git branch --merged | egrep -v $(git symbolic-ref refs/remotes/origin/HEAD | sed 's@^refs/remotes/origin/@@') | xargs git branch -d | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment