From 50d31b6c7ea8776501934c7b7ea9548b0f959bb0 Mon Sep 17 00:00:00 2001 From: nirenjan Date: Thu, 3 May 2018 13:49:24 -0700 Subject: [PATCH] Add script to update GitHub remotes to use the URL aliases --- scripts/git/git-update-github-remote | 32 ++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100755 scripts/git/git-update-github-remote diff --git a/scripts/git/git-update-github-remote b/scripts/git/git-update-github-remote new file mode 100755 index 0000000..4bba178 --- /dev/null +++ b/scripts/git/git-update-github-remote @@ -0,0 +1,32 @@ +#!/bin/bash +# +# Support script to update the origin github remote to use gh: or my: +# If the remote is of the form '.*github.com.nirenjan/foo\.git', change +# the remote to my:foo.git +# If the remote is of the form '.*github.com.foo/bar.git', change +# the remote to gh:foo/bar.git + +MY_GH_UID=nirenjan + +USAGE="Usage: $0 " + +REPOPATH="$1" + +if [[ -z "$REPOPATH" ]] +then + REPOPATH=$(git rev-parse --show-toplevel) +fi + +if [[ ! -r "$REPOPATH/.git/config" ]] +then + echo "ERROR: Not a git repository '$1'" >&2 + exit 1 +fi + +sed \ + -e "/url *= */s# [^ ]*github.com.$MY_GH_UID/\(.*\)\.git# my:\1.git#" \ + -e "/url *= */s# [^ ]*github.com.\(.*\)/\(.*\)\.git# gh:\1/\2.git#" \ + -i "$REPOPATH/.git/config" + +cd $REPOPATH +git remote -v