Skip to content

Instantly share code, notes, and snippets.

@johan johan/git-fold
Created Jun 7, 2017

Embed
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
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

This comment has been minimized.

Copy link

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
You can’t perform that action at this time.