Last active
December 14, 2015 03:19
-
-
Save deiga/5020323 to your computer and use it in GitHub Desktop.
Script to add upstream to current repo
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
#! /usr/bin/env ruby | |
require 'open-uri' | |
require 'json' | |
origin_url = `git remote show origin | awk '/Fetch/ {print $3}'` | |
origin_url.tr!("\n",'') | |
repo_name = origin_url.gsub('github.com','').gsub(/http[s]:\/\//, '').gsub('.git','') | |
repo_parts = repo_name.split('/').reject!(&:empty?) | |
url = "https://api.github.com/repos/#{repo_parts[0]}/#{repo_parts[1]}" | |
result = JSON.parse(open(url).read) | |
parent = result['parent'] | |
if parent | |
system %Q{git remote add upstream #{parent['clone_url']}} | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment