Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
snippets/git-https2ssh/git-https2ssh
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
executable file
31 lines (22 sloc)
825 Bytes
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 | |
# git-https2ssh.rb | |
# Author: William Woodruff | |
# ------------------------ | |
# Converts https remotes in git repos into ssh remotes. | |
# Incredibly unsafe. Don't use this. | |
# ------------------------ | |
# This program is licensed by William Woodruff under the MIT License. | |
# http://opensource.org/licenses/MIT | |
system('git rev-parse 2> /dev/null') or abort('No git repository found. Exiting.') | |
remote_info = `git remote -v` | |
if remote_info.empty? | |
abort('No remotes to change.') | |
end | |
if remote_info.match(/git@/) | |
abort('This repo is already using ssh remotes.') | |
end | |
user = remote_info.match(/(?:.+\/)(.+)(?:\/.+).git/)[1] | |
repo = remote_info.match(/[^\/]+.git/) | |
puts "Found user #{user} and repository #{repo}. Changing remote..." | |
`git remote set-url origin git@github.com:#{user}/#{repo}` | |
puts "Looks good." |