Last active
August 29, 2015 14:10
-
-
Save hyuki0000/e066a4cca2d1952b4c88 to your computer and use it in GitHub Desktop.
Change remote.origin.url from "https://..." to "git@...".
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 | |
url = `git config remote.origin.url` | |
puts "BEFORE: #{url}" | |
# https://[email protected]/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
See http://blog.textfile.org/20141128/git/