Git Configuration

This class uses the command line, so first you will need to find and open your terminal. For Windows, we recommend using Git Shell or Git Bash. For Mac or Linux, your default Terminal will work.

Before you can work with Git on the command line, you will need to set some basic configurations.

gif of following the directions below

  1. Open your Terminal application.
  2. Ensure Git 1.9.5 or :arrow_up: is installed, type:

     git --version
    

    If your Git version is below 1.9.5, check git-scm.com to download the latest version.

  3. Set your name in Git by replacing <YOUR NAME> with your first and last name:

     git config --global user.name <YOUR NAME>
    
  4. Set your email in Git by replacing <EMAIL> with the email associated with your GitHub account.

     git config --global user.email <EMAIL>
    
  5. Set line-ending behavior for your operating system:
    • On Windows:

      git config --global core.autocrlf true
      
    • On Mac and Unix-like systems:

      git config --global core.autocrlf input
      
  6. To see your current configurations, type:

     git config --list
    
Tell me why

Git uses config settings to customize your local working environment based on your preferences. You can do a lot with Git config, but we start with the basics.

Configuration Levels

Git allows you to set configuration options at three different levels.

  • --system: These are system-wide configurations. They apply to all users on this computer.
  • --global: These are the user level configurations. They only apply to your machine’s user account and will be applied to every repository you create or clone under your account.
  • --local: These are the repository level configurations. They only apply to the specific repository where they are set.

The default value for git config is --local. The local scope has precedence so setting something at this level will override settings at the global or system level.

What does autocrlf do?

If you’re using Git to collaborate with others on GitHub, ensure that Git is properly configured to handle line endings.

Every time you press return on your keyboard you’re actually inserting an invisible character called a line ending. Historically, different operating systems have handled line endings differently.

When you view changes in a file, Git handles line endings in its own way. Since you’re collaborating on projects with Git and GitHub, Git might produce unexpected results if, for example, you’re working on a Windows machine, and your collaborator has made a change in OS X.

For more information about autocrlf, see the GitHub Help documentation.

Taking Git Config Further

ProGit offers more information on customizing Git with git config.

Stuck? Open an issue in the repository for this class and mention @githubteacher for help from one of the GitHub trainers!
Continue