Configure Git client settings

Connect to your Git provider with an ssh keypair

Quite often I need to setup a computer to connect to my Git provider, in my case Github. The steps are easy enough though. For other Git providers the steps should be similar.

Install a Git client

Of course we need a Git client. Install one manually from https://git-scm.com/download/gui/windows for example.

Or if you are using chocolatey, run this.

choco install git

Git base configuration

Let’s setup a base configuration for Git.

git config --global user.name "<your name goes here>"
git config --global user.email "<your email address goes here>"
git config --global push.default simple
git config --global pull.rebase true
git config --global core.autocrlf input

These settings are stored in the file .gitconfig in your user folder. The user folder for Windows is c:\users\<user>\, for Linux this is /home/user.

Go here for more information about customizing you Git configuration.

Create a keypair

We need an ssh keypair to connect to GitHub. If you don’t already have a pair you need to create one.

ssh-keygen

alt ssh-keygen

You can enter a passphrase for your key or just press enter for no passphrase. This command creates 2 files in the folder .ssh in your user folder. The files are id_rsa and id_rsa.pub.

Open the file id_rsa.pub, its contents should look like this:

ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCoZlYxAdDmfcjnwiKyyTceK2ldPsV2KzG3EEDy9o8a7f7GiKfNpM/U3ZN4eFHK8DUoHlG+GGmKjvJ207VPsUQK0obi/7snaPu19m1wcoqnluaY2jcsTSiIHBFn+aVDWKNhc+UzbjZ+zFcHKqF0NIr1HaEpz4RV0N19UeyiIeqX7RpamkQX1MBTAHbQcBFB6eHJte9iWOpmMBmNManvU0rSZYWmdQzvK8+SFfHFB/93K1Cl4MLwG6gRfqGCmwgGmUiSgzG48uBa8N+cQCJie6ikbkKPV109kGVsnufx1kF/ka5/cgaABaxsKBXVxnpojUsFI1E6jS8lM5VZW32K23rB sven@PC-Sven

Configure GitHub to accept your public key

Browse to GitHub, click your avatar and choose Settings.

alt AddSshKey1

Click New SSH key.

alt AddSshKey2

Add a title and copy the contents of id_rsa.pub in the Key area.
Click Add SSH key.
Type your password to confirm.

alt AddSshKey3

The key is added to the list of SSH keys.

Tests your SSH connection to GitHub

ssh -T [email protected]

alt TestSshKey1

Huray!

Avatar
Sven de Windt
Systems Administrator

Systems engineer with an intrest in automation

comments powered by Disqus