Skip to content

Instantly share code, notes, and snippets.

@colantuomo
Last active June 2, 2021 13:45
Show Gist options
  • Save colantuomo/e948aca773be8b289045a1de9f23dde2 to your computer and use it in GitHub Desktop.
Save colantuomo/e948aca773be8b289045a1de9f23dde2 to your computer and use it in GitHub Desktop.
bash useful scripts

A List of useful bash scripts for MacOS and Linux

A smart way to checkout from branches:

function smart_checkout() {
    git branch
    echo "Type part of the branch you want to move?"
    read word
    for branch in $(git branch);
    do
        if [[ $branch == *$word* ]]; then
            git checkout $branch
            break;
        fi
    done
}

Get the current branch:

function get_branch() {
      git branch --no-color | grep -E '^\*' | awk '{print $2}' \
        || echo "default_value"
}

alias push_origin='git push -u origin "$(get_branch)"'
alias clear_branches='git branch | grep -v "master" | xargs git branch -D'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment