Skip to content

Instantly share code, notes, and snippets.

@shnjp
Last active February 20, 2017 09:30
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 shnjp/a086baef79582fe823cc94ec8b496645 to your computer and use it in GitHub Desktop.
Save shnjp/a086baef79582fe823cc94ec8b496645 to your computer and use it in GitHub Desktop.
remoteブランチをmasterでrebaseしてpushしなおす糞コマンド
#!/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
@shnjp
Copy link
Author

shnjp commented Feb 20, 2017

いきなりタイポしててワロタ

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