Skip to content

Instantly share code, notes, and snippets.

@hputzek
Last active February 23, 2024 11:47
Show Gist options
  • Save hputzek/bbc4fdbbebe9addd3056d886034c30e9 to your computer and use it in GitHub Desktop.
Save hputzek/bbc4fdbbebe9addd3056d886034c30e9 to your computer and use it in GitHub Desktop.
wbranch git alias

Adds git aliases to global git config.

git whelp shows this help text:

git wcb feature/test-123 will create and checkout the given branch name both in the project and in the base submodule

git wco feature/test-123 will checkout the given branch name both in the project and in the base submodule

git wp feature/test-123 will push the given branch name both in the project and in the base submodule

git config --global alias.wcb '!f() { branch_name=$1; if git show-ref --verify --quiet refs/heads/$branch_name; then echo "Branch $branch_name already exists in the current repository."; else git checkout -b $branch_name; fi; new_branch=$branch_name; cd ./base; if git show-ref --verify --quiet refs/heads/$new_branch; then echo "Branch $new_branch already exists in the base repository."; else git checkout -b $new_branch; fi; }; f'
git config --global alias.wco '!f() { branch_name=$1; if git show-ref --verify --quiet refs/heads/$branch_name; then git checkout $branch_name; else echo "Branch $branch_name does not exist in the current repository."; fi; new_branch=$branch_name; cd ./base; if git show-ref --verify --quiet refs/heads/$new_branch; then git checkout $new_branch; else echo "Branch $new_branch does not exist in the base repository."; fi; }; f'
git config --global alias.wp '!f() { branch_name=$1; if git show-ref --verify --quiet refs/heads/$branch_name; then git push origin $branch_name; else echo "Branch $branch_name does not exist in the current repository."; fi; new_branch=$branch_name; cd ./base; if git show-ref --verify --quiet refs/heads/$new_branch; then git push origin $new_branch; else echo "Branch $new_branch does not exist in the base repository."; fi; }; f'
git config --global alias.whelp '!echo -e "\ngit wcb feature/test-123 will create and checkout the given branch name both in the project and in the base submodule\n\ngit wco feature/test-123 will checkout the given branch name both in the project and in the base submodule\n\ngit wp feature/test-123 will push the given branch name both in the project and in the base submodule\n"'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment