Setting up Git and GitHub correctly the first time spares you hours of authentication headaches, rejected pushes, and messy commit logs down the road.
Here is the exact setup process: from creating your GitHub account to configuring local credentials and passwordless SSH authentication.
1. Creating Your GitHub Account
- Head to github.com/signup.
- Enter your primary email address, choose a secure password, and select a username.
Pro Tip: Pick a professional, memorable username (e.g.,
firstname-lastnameor your handle). It becomes your portfolio URL:github.com/your-username. - Complete the puzzle verification and enter the launch code sent to your inbox.
- Enable Two-Factor Authentication (2FA) immediately:
- Go to Settings > Password and authentication > Two-factor authentication.
- Use an authenticator app (1Password, Bitwarden, or Google Authenticator) and save your recovery codes somewhere safe. GitHub requires 2FA for all active developers.
2. Installing Git on Your Machine
Check if Git is already installed by opening your terminal or command prompt:
git --version
If it is not installed, install it for your operating system:
- Windows: Download and install from git-scm.com or run
winget install Git.Git. - macOS: Run
xcode-select --installor use Homebrew:brew install git. - Linux (Ubuntu/Debian): Run
sudo apt update && sudo apt install git -y.
3. Configuring Your Git Identity
Git tags every commit with an author name and email. Run these commands once on your system:
# Set your display name
git config --global user.name "Your Name"
# Set the email matching your GitHub account
git config --global user.email "your.email@example.com"
# Set the modern default branch name to 'main'
git config --global init.defaultBranch main
# Handle line endings cleanly (Windows: true | macOS/Linux: input)
git config --global core.autocrlf true
Verify your configuration:
git config --list --show-origin
4. Setting Up SSH Key Authentication
GitHub no longer accepts account passwords when pushing or pulling over HTTPS. Setting up an ED25519 SSH key gives you secure, passwordless authentication.
Step A: Generate the SSH Key
In your terminal, generate a new key pair (replace the email with your GitHub email):
ssh-keygen -t ed25519 -C "your.email@example.com"
- When prompted for a file location, press Enter to accept the default (
~/.ssh/id_ed25519). - Enter a passphrase (recommended for security) or press Enter twice for no passphrase.
Step B: Start the SSH Agent and Add Your Key
# Start SSH agent in the background
eval "$(ssh-agent -s)"
# Add your private key to the agent
ssh-add ~/.ssh/id_ed25519
Step C: Add the Public Key to GitHub
Print your public key and copy the entire output:
cat ~/.ssh/id_ed25519.pub
- On GitHub, navigate to Settings (top-right avatar) > SSH and GPG keys.
- Click New SSH key.
- Give it a descriptive title (e.g.,
Workstation-ThinkPadorMacBook-Pro). - Set Key type to
Authentication Key. - Paste the copied key into the Key field and click Add SSH key.
Step D: Test the Connection
Run this in your terminal:
ssh -T git@github.com
If everything is configured correctly, GitHub responds with:
Hi username! You've successfully authenticated, but GitHub does not provide shell access.
You are now fully set up to create repositories, stage commits, and push code without entering credentials every time.