Generate an SSH key, add it to GitHub, and use SSH remotes instead of HTTPS for authentication.
SSH Setup for GitHub
# Generate SSH key
ssh-keygen -t ed25519 -C "alice@example.com"
# Press Enter to accept default location: ~/.ssh/id_ed25519
# Start SSH agent
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519
# Copy public key
cat ~/.ssh/id_ed25519.pub
# Add to GitHub: Settings > SSH and GPG keys > New SSH key
# Test connection
ssh -T git@github.com
# Use SSH remote instead of HTTPS
git remote set-url origin git@github.com:user/repo.git
# Multiple GitHub accounts
# ~/.ssh/config
Host github-work
HostName github.com
User git
IdentityFile ~/.ssh/id_ed25519_work