Skip to content

Instantly share code, notes, and snippets.

@deiga
Last active December 14, 2015 03:19
Show Gist options
  • Save deiga/5020323 to your computer and use it in GitHub Desktop.
Save deiga/5020323 to your computer and use it in GitHub Desktop.
Script to add upstream to current repo
#! /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