Setting Up Git: SSH Keys and Global Configuration

Setting Up Git: SSH Keys and Global Configuration
1. Global Identity: Who Are You?
When you install Git, you MUST tell it your name and email. This is saved in the ~/.gitconfig file.
Pro Tip: Make sure this email matches your GitHub email exactly. If it doesn't, GitHub won't give you "Credit" (the green squares) for your work.
2. HTTPS vs. SSH: The Security Decision
- HTTPS (Old): Requires you to use "Personal Access Tokens." It's clunky and requires you to paste long strings of text every time you push.
- SSH (Modern): Uses a "Private Key" on your laptop and a "Public Key" on GitHub. Once set up, you never have to type a password again. It's faster, safer, and the industry standard.
3. Step-by-Step: Generating Ed25519 SSH Keys
In 2026, we don't use the old "RSA" keys. We use Ed25519 because it is faster and more secure.
- Generate:
ssh-keygen -t ed25519 -C "your@email.com" - Add to Agent:
ssh-add ~/.ssh/id_ed25519 - Copy: Open the
.pubfile and copy the text. - GitHub: Go to Settings -> SSH Keys -> New SSH Key, and paste the code.
4. The .gitignore File: Keeping it Clean
Not every file belongs in Git!
- You shouldn't save your
node_modules/folder (it's too big). - You MUST NOT save your
.envfiles (they contain your bank passwords and API keys). A.gitignorefile tells Git: "I see these files, but ignore them forever." Always include a standard.gitignorefor your specific language (Java/Python/Node) at the very start of every project.
Frequently Asked Questions
Is 'Global Config' enough?
Usually, yes. But if you have a Work Account and a Personal Account, you can use "Local Config" inside a specific folder to use a different email for that one project. Just remove the --global flag when running the command.
What is the 'Default Branch'?
In the old days it was "master." Modern platforms use "main." You can tell Git to always use "main" for every new project with:
git config --global init.defaultBranch main
Key Takeaway
Proper setup is the "Polishing of the tools." By configuring your global identity and mastering SSH authentication, you remove the friction from your daily workflow. You can focus on the Impact of your code, knowing that your security is handled and your attribution is perfect.
Read next: Git Branching Strategies: GitFlow vs. Trunk-Based →
Part of the GitHub Mastery Course — engineering the access.
