Skip to content

Instantly share code, notes, and snippets.

@d10r
Last active March 20, 2017 18:50
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 d10r/a1d9ca2fec1444f41f8b91fea0348645 to your computer and use it in GitHub Desktop.
Save d10r/a1d9ca2fec1444f41f8b91fea0348645 to your computer and use it in GitHub Desktop.
#!/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