Created
June 7, 2017 00:01
-
-
Save johan/04dee9ec7dfa1d780004ae8081b1d892 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 togit remote prune $origin
to the end, and make the first line#!/bin/sh -e