Last active
March 10, 2019 05:06
-
-
Save nhed/239aa94078b0b533d6f5 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/bash | |
# based on http://stackoverflow.com/a/18647857/652904 | |
declare PROGNAME="${0}" | |
function Usage() | |
{ | |
local -i EXITCODE=${1}; shift | |
echo "${@}" >&2 | |
cat<<_EOF_ >&2 | |
${@} | |
Usage: | |
${PROGNAME} <branchname> [git-branch-options] | |
git-branch-options are passed into git-branch after the branch name | |
_EOF_ | |
exit ${EXITCODE} | |
} | |
BRNAME=$1; shift | |
[ -z "${BRNAME}" ] && Usage 1 "Missing branchname" | |
# exit on fail | |
set -e | |
git branch "${BRNAME}" "${@}" | |
git checkout "${BRNAME}" | |
git config branch."${BRNAME}".remote origin | |
git config branch."${BRNAME}".merge refs/heads/"${BRNAME}" | |
git config branch."${BRNAME}".rebase true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Kudos to Gregory McIntyre, for his underappriciated answer on http://stackoverflow.com/a/18647857/652904. It did exactly what I needed, I just made it into a full, slightly safer script that also allows specification of
<start-point>
.