Created
February 21, 2024 00:55
-
-
Save lopugit/9e00dfee651269c20610d125fe51c0db to your computer and use it in GitHub Desktop.
Multi SSH KEY config for same hosts based on directory
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
Finally, multi ssh key config for same host git repo's :exploding_head: | |
https://superuser.com/questions/366649/ssh-config-same-host-but-different-keys-and-usernames | |
Alternative Git configuration to automatically switch accounts depending on repo path: | |
Create a file ~/.config/git/config.user1 containing: | |
[url "github_username1:"] | |
insteadOf = [email protected]: | |
Create a config.user2 file that's the same except with "github_username2". | |
In your main ~/.config/git/config file, tell Git to "include" one of the two files depending on which directory you're at: | |
[includeIf "gitdir:~/projects/"] | |
path = ~/.config/git/config.user1 | |
[includeIf "gitdir:~/src/work/"] | |
path = ~/.config/git/config.user2 | |
Now, whenever you're at ~/src/work/, cloning anything from [email protected]:[etc] will automatically rewrite the URL to github_username2:[etc]. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment