How-to

Git Setup: git config, Name, Email and SSH Keys

Updated: · Skillaria.Top

Basic Git setup comes down to git config --global user.name and git config --global user.email, which sign your commits, plus choosing an editor and a default branch name. To use GitHub without a password, generate an SSH key with ssh-keygen -t ed25519, add the public key to your account settings, and test the connection with ssh -T git@github.com.

Minimal Git setup in one minute

Run these four commands right after installing Git. Without the first two, Git will refuse to commit; the other two save you from common annoyances.

git config --global user.name "Jane Smith"
git config --global user.email "jane@example.com"
git config --global init.defaultBranch main
git config --global core.editor "code --wait"

Check the result:

$ git config --global --list
user.name=Jane Smith
user.email=jane@example.com
init.defaultbranch=main
core.editor=code --wait

Below we'll go through what each setting does, where Git stores it, and how to sign in to GitHub over SSH.

How git config works: three levels of settings

The git config command reads and writes options in one of three files. A narrower level overrides a broader one.

LevelFlagFileApplies to
System--system/etc/gitconfig (on Windows, in the Git installation folder)All users of the computer
Global--global~/.gitconfig or ~/.config/git/configAll your repositories
Local--local (default).git/config inside the repositoryThis repository only

Almost everything personal is set globally, and exceptions are set locally. For example, your work email for company projects is configured inside a specific repository, without the --global flag.

Handy git config commands

git config user.email                    # show the current value
git config --list --show-origin          # all settings and the file each comes from
git config --global --edit               # open ~/.gitconfig in your editor
git config --global --unset core.editor  # remove an option

The --show-origin flag is your best friend when debugging: it explains why you have the "wrong" email by showing which file the value came from.

Name and email: why they matter

Every commit permanently stores the author's name and email. They are not a login or password — Git doesn't verify them at all. But GitHub and GitLab use the email to link commits to your account: if the address doesn't match any verified email on your profile, the commits won't count toward your contribution graph and will show up without an avatar.

You can't change the name or email retroactively without rewriting history, so check your settings before your first commit.

Keep your real email private

In a public repository, anyone who looks at the history can see your email. GitHub provides a no-reply address like ID+username@users.noreply.github.com (under Settings → Emails). Set it in Git:

git config --global user.email "12345678+jane@users.noreply.github.com"

Different emails for work and personal projects

To avoid configuring every work repository by hand, use conditional includes. In ~/.gitconfig:

[includeIf "gitdir:~/work/"]
    path = ~/.gitconfig-work

And in ~/.gitconfig-work:

[user]
    email = jane@company.com

Now every repository inside ~/work/ automatically uses your work email. The trailing slash in the path is required.

Other useful Git settings

Editor

Git opens an editor for commit messages, interactive rebase and merges. By default it's often Vim. Options:

git config --global core.editor "code --wait"   # VS Code
git config --global core.editor "nano"          # Nano
git config --global core.editor "subl -n -w"    # Sublime Text

Default branch

init.defaultBranch main sets the name of the first branch in new repositories (available since Git 2.28). Without it, Git creates master and shows a hint about renaming it.

Line endings

git config --global core.autocrlf true    # Windows
git config --global core.autocrlf input   # macOS and Linux

This way the repository always stores LF line endings, and your team won't see bogus "changes" on every line of a file.

git pull behavior

If you don't set a strategy, modern Git will ask you to choose one explicitly when branches have diverged. Pick one:

git config --global pull.rebase false   # merge, the default behavior
git config --global pull.rebase true    # rebase, linear history
git config --global pull.ff only        # fast-forward only, otherwise an error

Non-ASCII file names and color

git config --global core.quotepath false
git config --global color.ui auto

Aliases

git config --global alias.st status
git config --global alias.co checkout
git config --global alias.br branch
git config --global alias.lg "log --oneline --graph --decorate --all"
git config --global alias.last "log -1 HEAD"

Now git lg draws the branch graph and git last shows the latest commit.

What ~/.gitconfig looks like after setup

[user]
    name = Jane Smith
    email = jane@example.com
[init]
    defaultBranch = main
[core]
    editor = code --wait
    autocrlf = input
    quotepath = false
[pull]
    rebase = false
[alias]
    st = status
    lg = log --oneline --graph --decorate --all

It's a plain text file: you can edit it by hand and copy it between computers.

Git login: how to sign in to GitHub

There is no git login command — a common trap for beginners. Git doesn't store an "account": authentication happens when you talk to the server (clone, push, fetch) over one of two protocols.

HTTPSSSH
URLhttps://github.com/user/repo.gitgit@github.com:user/repo.git
How you authenticateAccess token or browser sign-in (Credential Manager)An SSH key pair
Account passwordNot accepted since 2021Not needed
Best forWindows with Git Credential Manager, corporate proxiesmacOS, Linux, servers, CI

Signing in over HTTPS

With Git for Windows and macOS builds that include Git Credential Manager, your first git push opens a browser window to sign in to GitHub, and the credentials are saved in the system store. An alternative is GitHub's official CLI: gh auth login walks you through authorization and configures Git. If you're doing everything manually, create a Personal access token in GitHub settings (Developer settings) and enter it instead of your password.

SSH for Git: step-by-step setup

An SSH key is a pair of files: the private key stays with you, and you give the public key to GitHub. The server verifies that you own the private part, and you'll never be asked for a password again.

Step 1. Check for an existing key

ls -la ~/.ssh

If you already have id_ed25519 and id_ed25519.pub, skip to step 3.

Step 2. Generate a key

ssh-keygen -t ed25519 -C "jane@example.com"

Press Enter to save the key to the default path, and set a passphrase — it protects the key if your laptop is stolen. Ed25519 is the modern recommended algorithm. If an older system doesn't support it, use ssh-keygen -t rsa -b 4096 -C "jane@example.com".

Step 3. Add the key to ssh-agent

The agent keeps the decrypted key in memory so you don't type the passphrase on every push.

eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519

On macOS, add these lines to ~/.ssh/config so the passphrase is stored in the Keychain:

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

and run ssh-add --apple-use-keychain ~/.ssh/id_ed25519.

Step 4. Add the public key to GitHub

cat ~/.ssh/id_ed25519.pub

Copy the whole line, starting with ssh-ed25519. On GitHub, open Settings → SSH and GPG keys → New SSH key, paste the key and give it a clear name, such as "Laptop 2026". Never send or publish the file without .pub — that's your private key.

Step 5. Test the connection

$ ssh -T git@github.com
Hi jane! You've successfully authenticated, but GitHub does not provide shell access.

On the first connection, SSH asks whether to trust the host — compare the fingerprint with the ones published in GitHub's documentation and answer yes.

Step 6. Switch the repository to SSH

If you cloned the repository over HTTPS, change the remote URL:

git remote -v
git remote set-url origin git@github.com:jane/my-project.git
git push

Multiple GitHub accounts on one computer

An SSH key can be linked to only one GitHub account. For work and personal accounts, create two keys and host aliases in ~/.ssh/config:

Host github-work
    HostName github.com
    User git
    IdentityFile ~/.ssh/id_ed25519_work
    IdentitiesOnly yes

Clone work repositories through the alias: git clone git@github-work:company/app.git. Combined with includeIf for the email, this gives you fully separate work and personal environments.

Common setup errors

"Please tell me who you are"

user.name and user.email aren't set. Run the commands from the top of this article and commit again.

"Permission denied (publickey)"

GitHub didn't find a matching key. Check that the key is loaded in the agent (ssh-add -l) and the public part is added to your account; ssh -vT git@github.com shows the details.

"Support for password authentication was removed"

You entered your account password over HTTPS. Use a token, sign in via Credential Manager, or switch to SSH.

Commits on GitHub without an avatar

The email in git config user.email isn't added to your GitHub profile. Add it under Settings → Emails — older commits will be linked automatically.

Port 22 is blocked on your network

GitHub also accepts SSH on port 443. In ~/.ssh/config, set Host github.com, Hostname ssh.github.com, Port 443.

Setup checklist for a new computer

  1. Install Git and check git --version.
  2. Set user.name, user.email, init.defaultBranch and your editor.
  3. Copy over or create ~/.gitconfig with aliases and a pull strategy.
  4. Generate a new SSH key (don't copy an old private key between machines unless you have to) and add it to GitHub.
  5. Test access with ssh -T git@github.com and clone your working repository using the SSH URL.

A separate key per device also means that if you lose a laptop, you only need to delete one key on GitHub without affecting access from your other machines.

Summary

Setting up Git takes three steps: set your name and email with git config --global, choose an editor, default branch and pull strategy, and then connect to GitHub — the simplest and most reliable way is an SSH key. Remember that there is no git login command: authentication happens when you talk to the server. Configuration and SSH access are covered hands-on in the Git course.

FAQ

Where are Git settings stored on Windows?

Global settings are in C:\Users\Name\.gitconfig, local ones in .git\config of each repository. git config --list --show-origin shows the exact locations.

How do I reset Git settings?

Delete or rename ~/.gitconfig and Git falls back to its defaults. To remove a single option, use git config --global --unset name.

Can I use one SSH key for both GitHub and GitLab?

Yes, the same public key can be added to different services. The only restriction is that on GitHub a key can belong to just one account.

How do I sign commits so GitHub shows them as Verified?

Set up signing with a GPG or SSH key: for example, git config --global gpg.format ssh, user.signingkey pointing to your public key, and commit.gpgsign true, then add the key on GitHub as a Signing key.

Do I need to configure Git again after updating it?

No, updates don't touch ~/.gitconfig or the keys in ~/.ssh — all your settings are kept.

Learn this topic on video

This topic is covered in depth with practice in the course “Git from Scratch to Confident Developer”.

Go to course