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.
git config --global user.name "Your Name"
git config --global user.email "your@email.com"
git config --global init.defaultBranch main2. Generate an SSH Key
Using Ed25519 - it’s more secure and faster than RSA.
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.
# Start the agent
eval "$(ssh-agent -s)"
# Add the key
ssh-add ~/.ssh/id_ed255194. Link to GitHub
Copy the public key to your clipboard to paste it into your provider's settings.
cat ~/.ssh/id_ed25519.pub5. Test the Connection
Check if the handshake works.
ssh -T git@github.comNote: If you are on macOS, you might need to create/edit ~/.ssh/config to automatically load keys into the agent on startup:
Host github.com
AddKeysToAgent yes
UseKeychain yes
IdentityFile ~/.ssh/id_ed255196. 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.
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:
git config --global core.autocrlf trueOn Linux/macOS/WSL:
git config --global core.autocrlf inputSilence CRLF Warnings
If the "LF will be replaced by CRLF" warnings show when using Git Bash on Windows:
git config --global core.safecrlf false