Skip to content

Instantly share code, notes, and snippets.

@johan
Created June 7, 2017 00:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johan/04dee9ec7dfa1d780004ae8081b1d892 to your computer and use it in GitHub Desktop.
Save johan/04dee9ec7dfa1d780004ae8081b1d892 to your computer and use it in GitHub Desktop.
#! /bin/sh
# git-fold (a k a "git fold") fetches the main branch upstream,
# and if your current branch has already been landed upstreams,
# then check out the master branch, delete the landed branch,
# and catch up master with origin
# optional reference branch to check folding against and move to - or master
master="${1:-master}"
# optional reference origin to fetch from and pull up to
origin="${2:-origin}"
git fetch "$origin"
branch="$(git symbolic-ref --short HEAD)"
delete="$(git branch --merged "${origin}/${master}" \
| cut -b 3- \
| egrep -v "^${master}$" \
| egrep "^${branch}$")"
if [ -n "$delete" ]; then
git checkout "$master"
git branch -d "$delete"
git pull --ff-only
fi
@dbushong
Copy link

Nice! I have a version I called git close-pr that didn't do as good a job finding the parent branch. Suggestion: add a call to git remote prune $origin to the end, and make the first line #!/bin/sh -e

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment