Configuring Git command line and editor

We have a longer version of this in the installation instructions. But for clarity, we will review the most important parts here.

You don’t need to set these if you work only through the GitHub web interface. If you use VS Code or other editors or integrated development environments, the editor might prompt you to set these up.

These configuration settings are saved in a file called .gitconfig in your home directory. If this file exists, editors like VS Code will use this configuration.

If you want to see your configuration settings, you can use the command (--show-origin means it shows the file where each setting is defined):

$ git config --list --show-origin

Name and email address for Git commit metadata

Git commits carry metadata about the author and two things you will always need to define somewhere are:

$ git config --global user.name "Your Name"
$ git config --global user.email yourname@example.com

For the email address we recommend to use the one you use for your GitHub account. If you prefer to not use it, you can instead use YOUR_GITHUB_USERNAME@users.noreply.github.com as the email address (replace YOUR_GITHUB_USERNAME). This means that nobody can write to this email address, but GitHub will still be able to connect your contributions with your GitHub account.

Note that these can, in theory, be anything: this is just data, not a registration or identity requirement.

Default branch name

The default branch name in Git has been master for a long time, but it is changing to main in many places. We recommend to set it to main for new repositories that you create locally:

$ git config --global init.defaultbranch main

Useful alias for the command line

We recommend to define an alias (shortcut) in Git, to be able to nicely visualize branch structure in the terminal without having to remember a long Git command:

$ git config --global alias.graph "log --all --graph --decorate --oneline"

We have an own section about aliases: Aliases and configuration.

Default text editor for commit messages

Git sometimes needs to start a text editor for you to enter messages (unless you create commits from inside an editor or on the web). This may have already been set to something (like VS Code), but if not nano is usually a safe choice:

$ git config --global core.editor nano

The installation instructions text editor page gives ways to set other editors, or do a web search for “git set editor to [editor name]”.

Authenticating to GitHub: SSH or HTTPS or VS Code?

How does GitHub know who you are? We discuss here three options:

  • SSH is the classic method, using Secure Shell Protocol remote connection keys.

  • HTTPS works with the Git Credential Manager, which is an extra add-on that works easily in Windows and Mac.

  • VS Code editor can authenticate with GitHub using its own authentication method.

Read how to install them from the installation instructions.

Test which one you should use:

Try this command:

$ ssh -T git@github.com

If it returns Hi USERNAME! You've successfully authenticated, ..., then SSH is configured and the following steps will work with the SSH cloning.

See our installation instructions to set up SSH access.

From now on, if you know that SSH works, you should always select SSH as the clone URL from GitHub, or translate the URL to start with the right thing yourself: git@github.com: (with the :).