Git Config
Learn how to set up Git for your local machine by familiarizing yourself with the Git config command.
Installing Git
The Git software is a powerful command-line tool that you can install on your machine, whether you use Windows, macOS, or Linux. There is a command-line terminal available below for you to try out various Git commands as well.
You can learn how to install Git for whichever operating system you use through this link.
From this point forward, we will rely on the command-line terminal, so your familiarity with the terminal will help you a lot.
Once you have Git installed on your machine, you will be able to use all the Git commands locally.
To verify that Git is installed successfully in the system, try typing in the following command in the terminal provided at the end of this lesson:
git --version
If Git is properly installed, the command above should display the installed version of Git that you are going to use.
Note: You will be provided with terminals in the entire course, which will have Git installed already, so you won’t need to install it on the platform.
The git config
command
The git config
command works for a large variety of cases. Moreover, the config command works on different levels.
Our main goal is to set our credentials that will identify our contributions and changes in the project source code. Doing so will help us identify and differentiate between the changes made by various contributors.
The config command works on different levels
We can set our credentials to be limited to a particular project, i.e., locally, or we can set them up globally. Finally, we can also use the config command to work on a system level.
Setting configurations at a local level will only affect the working project directory. Using the global configuration will result in the same configurations to apply to all our repositories that the currently logged in user for that machine makes, except for the projects where the user has assigned a different local configuration. Configurations that are set up on a system level will, by default apply to all the users on that particular computer.
Setting our email and username for Git
We will set up our name and email globally for Git by using the following commands:
git config --global user.email "educative_learner@example.com"
Similarly, we will also set up our username too:
git config --global user.name "Educative Learner"
You can also test and verify these commands by entering them in the terminal below:
You can verify your configurations for setting up the email and username by typing in the commands:
git config user.email
git config user.name
If they work fine, you should be able to see your desired email and username printed on the terminal.
Now that you have set up your information using the git config
command at a global level, let’s proceed forward with creating a new project and initializing Git to track it.
Configure Git with a name and email of your choice
In the terminal below, and in every terminal you will be provided in the course, you are given two configurable environment variables for inserting an email and name of your preference. Click on the edit button present below, and change the default email and name to what you would prefer.
This change will be reflected in all the proceeding terminals in the course. You can also configure Git using the commands above, but those changes will be restricted to that specific terminal. If you’d like to continue forward with a name and email of your own preference on the platform, you will need to use the environment variables, since they are configured globally, and their values will remain persistent throughout the course.
Note: The environment variables are used here to make sure the course is more interactive for you as a learner with the terminals provided. You do not need to rely on environment variables to configure Git otherwise and can proceed forward with the course using the default configurations.