Last active
November 26, 2016 14:17
-
-
Save kitsuyui/ae1e8a61ae5b55b84f8b166dfefe840f to your computer and use it in GitHub Desktop.
2 つの異なる GitHub アカウントの SSH を使い分けたい場合のやり方 ref: http://qiita.com/kitsuyui/items/7228f2c1570d8ee108e4
This file contains hidden or 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
Host github.com | |
IdentityFile /dev/null | |
Host foo.github.com | |
User git | |
HostName github.com | |
IdentityFile ~/.ssh/foo.id_rsa | |
Host bar.github.com | |
User git | |
HostName github.com | |
IdentityFile ~/.ssh/bar.id_rsa |
This file contains hidden or 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
$ git config --global alias.config-foo '!~/.bin/git-config-foo' |
This file contains hidden or 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
$ git config-foo |
This file contains hidden or 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 bash | |
set -eu | |
USERNAME='foo' | |
EMAIL='[email protected]' | |
SSH_ALIAS='ssh://foo.github.com/' | |
GPG_KEY='XXXXX' | |
upsert_config(){ | |
local key="$1" | |
local val="$2" | |
if git config --get "$key" >/dev/null 2>&1 ; then | |
git config --replace "$key" "$val" | |
else | |
git config --add "$key" "$val" | |
fi | |
} | |
upsert_config user.name "$USERNAME" | |
upsert_config user.email "$EMAIL" | |
upsert_config url."$SSH_ALIAS".insteadOf '[email protected]:' | |
# ↓ GPG の設定が必要な場合はアンコメントアウト | |
# upsert_config user.signingkey "$GPG_KEY" | |
# upsert_config gpg.program 'gpg1' | |
# upsert_config commit.gpgsign true |
This file contains hidden or 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
Host github.com | |
IdentityFile /dev/null | |
Host foo.github.com | |
User foo | |
HostName github.com | |
IdentityFile ~/.ssh/foo.id_rsa | |
Host bar.github.com | |
User bar | |
HostName github.com | |
IdentityFile ~/.ssh/bar.id_rsa |
This file contains hidden or 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
$ git config --add url."ssh://bar.github.com/".insteadOf '[email protected]:' |
This file contains hidden or 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
$ git config --add url."ssh://foo.github.com/".insteadOf '[email protected]:' |
This file contains hidden or 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
$ git config --add url."ssh://bar.github.com/".insteadOf '[email protected]:' |
This file contains hidden or 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
$ git config --add url."ssh://foo.github.com/".insteadOf '[email protected]:' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment