Skip to content

Instantly share code, notes, and snippets.

@chuckg
Created January 9, 2017 22:56
Show Gist options
  • Save chuckg/a97ad7af228c53f05f1f9c378073afe2 to your computer and use it in GitHub Desktop.
Save chuckg/a97ad7af228c53f05f1f9c378073afe2 to your computer and use it in GitHub Desktop.
golang tools
go_clone_usage() {
echo
echo 'HEY DUMBO ... the following variables must be exported:'
echo
echo " - \$REPO_UPSTREAM"
echo " - \$REPO_FORK"
echo
echo 'Usage:'
echo
echo " REPO_UPSTREAM=github.com/klarna/eremetic"
echo " REPO_FORK=github.com/chuckg/eremetic"
echo " go_clone"
}
go_clone() {
if [ -z "$REPO_UPSTREAM" ]; then
go_clone_usage
elif [ -z "$REPO_FORK" ]; then
go_clone_usage
else
echo "Cloning $REPO_UPSTREAM ..."
go get $REPO_UPSTREAM
echo
echo "Changing current working directory to $GOPATH/src/$REPO_UPSTREAM ..."
cd $GOPATH/src/$REPO_UPSTREAM
# Switch the remotes around
echo "Renaming remote 'origin' to 'upstream' for $REPO_UPSTREAM ..."
git remote rename origin upstream
echo
echo "Adding new origin remote to $REPO_FORK ..."
git remote add origin git@$(echo $REPO_FORK | sed 's/\//:/').git
echo
echo "Fetching remotes ..."
git fetch upstream
git fetch origin
echo
# Remove upstream/master and replace with origin/master on master.
echo "Removing upstream/master and replacing with new origin/master ..."
git checkout origin/master
git branch -d master
git co -b master origin/master
echo
echo "Done cloning $REPO_UPSTREAM"
echo
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment