Skip to content

Instantly share code, notes, and snippets.



Created Jun 7, 2017
What would you like to do?
#! /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
# optional reference origin to fetch from and pull up to
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

This comment has been minimized.

Copy link

@dbushong dbushong commented Jun 12, 2017

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