Skip to content

Instantly share code, notes, and snippets.

@iagoalonsomrf
Last active March 27, 2025 10:50
Show Gist options
  • Select an option

  • Save iagoalonsomrf/57a78d7b12bdfc9d7d020e5475186ba4 to your computer and use it in GitHub Desktop.

Select an option

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
if [ -z "$1" ]
then
DEFAULT_BRANCH="master"
else
DEFAULT_BRANCH="$1"
fi
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