Last active
February 20, 2017 09:30
-
-
Save shnjp/a086baef79582fe823cc94ec8b496645 to your computer and use it in GitHub Desktop.
remoteブランチをmasterでrebaseしてpushしなおす糞コマンド
This file contains hidden or 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 | |
set -e | |
source "$(git --exec-path)/git-sh-setup" | |
USAGE="<remote> <branch>" | |
function _remaster_pr() { | |
local readonly remote=$1 | |
local readonly branch=$2 | |
if [[ $# == 2 ]]; then | |
local readonly current_branch=`git rev-parse --abbrev-ref HEAD` | |
local readonly temp_branch=`make_temp_branch_name` | |
echo $temp_branch | |
git fetch $remote --prune | |
git checkout -B $temp_branch "${remote}/${branch}" | |
git rebase "${remote}/master" | |
git push --force-with-lease $remote "HEAD:${branch}" | |
git checkout $current_branch | |
git branch -D $temp_branch | |
else | |
usage | |
fi | |
} | |
function make_temp_branch_name() { | |
while : | |
do | |
local readonly branch_name=temp-`cat /dev/urandom | LC_CTYPE=C tr -dc 'a-z' | head -c 16` | |
if ! git rev-parse $branch_name > /dev/null 2>&1 ; then | |
# echo !!"${branch_name}"!! > /dev/stderr | |
echo "${branch_name}" | |
return | |
fi | |
done | |
} | |
_remaster_pr $1 $2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
いきなりタイポしててワロタ