Skip to content

Instantly share code, notes, and snippets.

@txemaleon
txemaleon / check_git_branch_exists.sh
Created April 1, 2023 10:27 — forked from iridiumcao/check_git_branch_exists.sh
How to check if a git branch exists in the local/remote repository?
# Local:
# https://stackoverflow.com/questions/21151178/shell-script-to-check-if-specified-git-branch-exists
# test if the branch is in the local repository.
# return 1 if the branch exists in the local, or 0 if not.
function is_in_local() {
local branch=${1}
local existed_in_local=$(git branch --list ${branch})
if [[ -z ${existed_in_local} ]]; then
echo 0