Skip to content

Instantly share code, notes, and snippets.

@hyuki0000
Last active August 29, 2015 14:10
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hyuki0000/e066a4cca2d1952b4c88 to your computer and use it in GitHub Desktop.
Save hyuki0000/e066a4cca2d1952b4c88 to your computer and use it in GitHub Desktop.
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
Copy link
Author

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