Gitting Started

logo for git, a client for source control management

Rather than continue to Google, Use, Forget, Repeat everything I need to remember about git, I chose to just keep track of it the old fashioned way – so I can write, use, forget, google, repeat 🙂

This will therefore be quite a dynamic document.

Multiple Identities

As I often use the same device for personal and work so it helps to be able to keep things separate, especially;

Git Configurations

You can easily maintain different git configurations for different purposes based on repo folder path. Inside your global gitconfig, add the following

[includeIf "gitdir/i:~/Code/work/"]
    path = ~/Code/work/gitconfig

[includeIf "gitdir/i:~/Code/mtr/"]
    path = ~/Code/mtr/gitconfig
  • gitdir/i: – to match on the git path, case insensitive (/i)
  • the path you are matching on, with a trailing slash
  • the path to the file containing the values, formatted correctly, you wish to use

Enter the relevant information within each of the gitconfig files.

[user]
    name = "Edward Douse"
    email = "marv@marvtherobot.com"
    signingKey = ""

To make sure everything is working, enter a git intialised repo under each of the folder paths and execute git config --show-origin --get user.email and check that the values returned are correct.

> pwd
/Users/marv/Code/work/projectA
> git config --show-origin --get user.email
me@whereiwork.com
> pwd
/Users/marv/Code/mtr/PsProject
> git config --show-origin --get user.email
marv@whereilive.com

SSH Keys

I prefer to keep two sets of ssh keys running. This helps when using shared tools such as Azure DevOps where my publish ssh key is already registered for my other account; trying to add this same public key will give an error that they key is already in use. This appears to be across Azure DevOps itself rather than organisation as I’ve never loaded my personal ssh key in.

Create another ssh key pair:

ssh-keygen -t rsa -C "me@whereiwork.com"

I then follow the usual instructions, appending my _companyname to the id_rsa suggestion, ensuring I match the default path too to keep everything together.

>pwd
/Users/marv/.ssh/

>ls
config
id_rsa      id_rsa_companyname
id_rsa.pub  id_rsa_companyname.pub

Add new key pair:

Once generated load them into the local ssh client.

ssh-add ~/.ssh/id_rsa_companyname

Which I think is all that is needed.

Limiting use:

A further step is to restrict where this ssh key will be used.

code ~/.ssh/config

Add the following which should only use the new ssh key for that host and the default key for all others. I want to look into this more in the near future to see if I can be more granular around URIs and to see how useful this really is.

Host ssh.dev.azure.com-work
    HostName ssh.dev.azure.com
    User git
    IdentityFile ~/.ssh/id_rsa_companyname

Share

Let me know what you think in the comments.