Setting up Git & SSH on a new machine

2 min read

New device, fresh start. Here is the sequence for getting Git configured and authenticated via SSH.

1. Configure Git Identity

Set your global name and email. This attaches your identity to your commits.

shell
git config --global user.name "Your Name"
git config --global user.email "your@email.com"
git config --global init.defaultBranch main

2. Generate an SSH Key

Using Ed25519 - it’s more secure and faster than RSA.

shell
ssh-keygen -t ed25519 -C "your@email.com"

When prompted, use a passphrase unless this is a throwaway machine. Otherwise, press Enter to save it in the default location (~/.ssh/id_ed25519).

3. If You're Using a Passphrase: Add Key to the SSH Agent

Ensure the agent is running and store the key so you don't have to re-type passphrases constantly.

shell
# Start the agent
eval "$(ssh-agent -s)"

# Add the key
ssh-add ~/.ssh/id_ed25519

4. Link to GitHub

Copy the public key to your clipboard to paste it into your provider's settings.

shell
cat ~/.ssh/id_ed25519.pub

5. Test the Connection

Check if the handshake works.

shell
ssh -T git@github.com

Note: If you are on macOS, you might need to create/edit ~/.ssh/config to automatically load keys into the agent on startup:

shell
Host github.com
  AddKeysToAgent yes
  UseKeychain yes
  IdentityFile ~/.ssh/id_ed25519

6. Optional: My personal configs to make git easier

To avoid the default Vim editor and manage cross-platform line endings, apply these global configurations.

Use VS Code as the Default Editor

The --wait flag is essential. It tells Git to wait for you to close the VS Code window before proceeding with the commit.

shell
git config --global core.editor "code --wait"

Note: Ensure the code command is in your PATH.

Handle Line Endings (CRLF vs LF)

Windows uses CRLF, while Linux and macOS use LF. Mixing these in a repo causes unnecessary diffs.

On Windows:

shell
git config --global core.autocrlf true

On Linux/macOS/WSL:

shell
git config --global core.autocrlf input

Silence CRLF Warnings

If the "LF will be replaced by CRLF" warnings show when using Git Bash on Windows:

shell
git config --global core.safecrlf false