Skip to content

Instantly share code, notes, and snippets.

@elliz
Created May 13, 2020 05:50
Show Gist options
  • Save elliz/fd4b7547245552ae24043ffc1a7b42d5 to your computer and use it in GitHub Desktop.
Save elliz/fd4b7547245552ae24043ffc1a7b42d5 to your computer and use it in GitHub Desktop.

Different git creds for different repos

TODO confirm this for windows

In global gitconfig -- on windows in Program Files/Git/etc

# xxxxxxx Projects
[includeIf "gitdir:<path to dir you're interested in>/**"]
    path = path to specific gitconfig created for this project

Which tells git that if it's within my xxx directory, to load the gitconfig at that path, which looks like:

[user]
    name = your name
    email = email to use for this project
# Reconfigure SSH
[core]
    sshCommand = ssh -F <path to ssh file>

Which modifies git's SSH command to use a custom SSH config, which looks like:

# Anglo American SSH Config
Host <???????> *
    HostName ssh.dev.azure.com
    User git
    IdentityFile ~/.ssh/id_rsa_xxxxxxxxxxxxx
    IdentitiesOnly yes
    UserKnownHostsFile ~/.ssh/knownhosts_xxxxxxxxxxxxxx

Which tells SSH to use an identity file I created for xxxxxx, which looks like:

-----BEGIN OPENSSH PRIVATE KEY-----
b3BlbnNzaC1rZXkNOTACHANCEINHELLAAAAEbm9uZQAAAAAAAAABAAACFwAA
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment