Last active
August 6, 2018 23:22
-
-
Save doingweb/d97de373c3bd5bd94d4d007c0b923564 to your computer and use it in GitHub Desktop.
Git workflow shortcut functions for ZSH
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
extract-ticket-id-from-branch() { | |
echo $1 | grep -o -E '[A-Z]+-[0-9]+' | |
} | |
git-start-work() { | |
branch="$1" | |
ticket_id=$(extract-ticket-id-from-branch $branch) | |
if [[ "$#" == 0 || -z "$ticket_id" ]]; then | |
echo "Usage: git-start-work [branch with ticket ID]" | |
return | |
fi | |
repo_name=$(basename $(pwd)) | |
worktree_path="../$repo_name-$ticket_id" | |
git worktree add -b $branch $worktree_path master | |
cp -r .vscode $worktree_path | |
} | |
git-end-work() { | |
branch="$1" | |
ticket_id=$(extract-ticket-id-from-branch $branch) | |
if [[ "$#" == 0 || -z "$ticket_id" ]]; then | |
echo "Usage: git-end-work [branch with ticket ID]" | |
return | |
fi | |
repo_name=$(basename $(pwd)) | |
worktree_path="../$repo_name-$ticket_id" | |
git worktree remove $worktree_path | |
git branch -d $branch | |
git push origin --delete $branch | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment