Last active
March 20, 2017 18:50
-
-
Save d10r/a1d9ca2fec1444f41f8b91fea0348645 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 | |
# adjusts remotes of local repo if forking after clone (move origin -> upstream, add fork as origin) | |
set -u | |
set -e | |
die () { | |
echo >&2 "### $@" | |
exit 1 | |
} | |
username=d10r | |
# get upstream url (which is currently configured for origin remote) | |
upstream_url=$(git config --get remote.origin.url) | |
echo $upstream_url | grep -q "github.com" || die "seems not to be a github repo" | |
# build fork url | |
regex="s/.*https:\/\/github.com\/.*\/\(.*\)/ssh:\/\/git@github.com\/$username\/\1/" | |
fork_url=$(echo $upstream_url | sed $regex) | |
# set fork as new origin remote | |
git remote set-url origin $fork_url | |
# add upstream | |
git remote add upstream $upstream_url | |
echo "moved origin to upstream and added fork as new origin: $fork_url" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment