Skip to content

Instantly share code, notes, and snippets.

@iagoalonsomrf
Created September 14, 2023 11:35
Show Gist options
  • Save iagoalonsomrf/57a78d7b12bdfc9d7d020e5475186ba4 to your computer and use it in GitHub Desktop.
Save iagoalonsomrf/57a78d7b12bdfc9d7d020e5475186ba4 to your computer and use it in GitHub Desktop.
Delete your working branch after it's merged, and pull the default branch
#!/usr/bin/env bash
DEFAULT_BRANCH="master"
CURRENT_BRANCH=$(git branch --show-current)
if git checkout "$DEFAULT_BRANCH"
then
git pull
if ! git branch -d "$CURRENT_BRANCH"
then
printf 'Delete anyway? (y/n)? '
read -r answer
if [ "$answer" != "${answer#[Yy]}" ]
then
git branch -D "$CURRENT_BRANCH"
fi
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment