Create a gist now

Instantly share code, notes, and snippets.

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:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment