mirror of
https://github.com/tj/git-extras.git
synced 2026-09-10 07:26:17 -04:00
update git-fork to add remotes refs as ssh change fork source remote name to upstream add man page for git-fork
34 lines
838 B
Bash
Executable file
34 lines
838 B
Bash
Executable file
#!/usr/bin/env sh
|
|
|
|
abort() {
|
|
echo $@
|
|
exit 1
|
|
}
|
|
|
|
# validate repo url
|
|
test -z "$1" && abort "github repo needs to be specified as an argument"
|
|
|
|
# validate user
|
|
echo "Enter your github username"
|
|
read user
|
|
[ "$user" = 'n' ] && abort "git username required"
|
|
|
|
# extract owner + project from repo url
|
|
project=${1##*/}
|
|
owner=${1%/$project}
|
|
owner=${owner##*/}
|
|
|
|
# validate
|
|
[ -z "$project" -o -z "$owner" ] && abort "github repo needs to be specified as an argument"
|
|
|
|
# create pull request
|
|
curl -X POST -u "$user" "https://api.github.com/repos/$owner/$project/forks"
|
|
[ $? = 0 ] || abort "fork failed"
|
|
|
|
# clone forked repo into current dir
|
|
git clone "git@github.com:$user/$project" "$project"
|
|
|
|
# add reference to origin fork so can merge in upstream changes
|
|
cd "$project"
|
|
git remote add upstream "git@github.com:$owner/$project"
|
|
git fetch upstream |