このように書いてあって、このスクリプトは、
private-ghq get git@github.com:hogehgoe/fugafuga
を実行したときに、cloneしたリポジトリ直下に.gitconfigを自動的に作成してくれるもの。つまり、複数アカウントに対応するためには別のことをする必要がある。
github_host = "private.github.com" username = "xxxx" email = "xxxx" if ARGV[0] == "get" args = [] repo = "" ARGV[1..-1].each do |arg| repo = arg if arg.match(/^git@github.com/) args << arg.gsub(/^git@github.com/, "git@#{github_host}") end system "ghq", "get", *args exit_code = $?.to_i unless repo.empty? dir = repo.match(/^git@github.com:([^.]*)(\.git)?/)[1] ghq_root = `ghq root`.chomp Dir.chdir(File.join(ghq_root, "#{github_host}/#{dir}/")) do system "git config user.name '#{username}'" system "git config user.email #{email}" end end exit exit_code else exec "ghq", *ARGV end
それは、こういうこと。
- 普段使いとは別のssh鍵を作成する(同じ鍵を複数アカウントで使い回すことはできない)
- 別アカウントに1で作ったssh鍵を登録する
- .ssh/configに以下のような設定を追加する
Host github-private
User git
Port 22
HostName github.com
IdentityFile ~/.ssh/github-private_rsa
TCPKeepAlive yes
IdentitiesOnly yes
- 実際にcloneするときは、
git@github-private:nonakaryuichi/git-test.git
みたいな感じで実行する。