Instantly share code, notes, and snippets.

Embed
What would you like to do?
Change remote.origin.url from "https://..." to "git@...".
#!/usr/bin/env ruby
url = `git config remote.origin.url`
puts "BEFORE: #{url}"
# https://YOURNAME@example.com/YOURNAME/myrepo.git
if url.match(/https:\/\/([^\/@]+@)?([^\/]+)\/([^\/]+)\/(.+)\.git/)
optional_login_name, domain, name, repo = $1, $2, $3, $4
cmd = "git remote set-url origin git@#{domain}:#{name}/#{repo}.git"
puts cmd
system(cmd)
url = `git config remote.origin.url`
puts "AFTER: #{url}"
else
puts "Unexpected remote.origin.url."
end
# vim: set filetype=ruby:
@hyuki0000

This comment has been minimized.

Show comment
Hide comment
Owner

hyuki0000 commented Nov 30, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment