Before using Git, you need to make sure it is installed on your computer and complete a small amount of initial configuration. This setup is straightforward and usually only needs to be done once. After that, most of your Git projects can use the same settings.
Installing Git
On Windows, the most common option is Git for Windows. During installation, you will see several configuration choices. If you are new to Git and are not sure what they mean, the default options are usually fine. After installation, you can run Git from PowerShell, Command Prompt, Git Bash, or the built-in terminal in VS Code.
On macOS, start by opening Terminal and running:
git --versionGit may already be available on your Mac. If it is not, macOS will usually guide you through installing the required developer tools.
On Linux, Git can normally be installed through your system's package manager. For example, on Ubuntu or Debian you can run:
sudo apt install gitOn Fedora, you can use:
sudo dnf install gitThe installation process is slightly different across operating systems, but once Git is installed, the commands are essentially the same. The rest of this tutorial will therefore work in the same way on Windows, macOS, and Linux.
Checking the Installation
After installation, open a terminal and run:
git --versionIf Git is installed correctly, you should see something similar to:
git version 2.50.0Your version number may be different, and that is perfectly fine. As long as Git prints a version number, the installation is working.
Setting Your Name and Email
Every Git commit contains information about who created it, so Git needs a name and an email address for your commits. You can set your name with:
git config --global user.name "Your Name"For example:
git config --global user.name "Alex Chen"Then set your email address:
git config --global user.email "[email protected]"For example:
git config --global user.email "[email protected]"The name does not have to exactly match your GitHub username. It is mainly used to identify who created a commit. If you plan to push your work to GitHub, it is usually a good idea to use an email associated with your GitHub account or a GitHub-provided private email address.
The --global option means that the setting will be used as the default for Git repositories on your computer. In other words, once you configure your name and email globally, you normally do not need to configure them again for every new project.
KNOWLEDGE QUIZ
--global mean in the user-name configuration command?
Checking Your Git Configuration
To view your current Git configuration, run:
git config --listYou may see output such as:
user.name=Alex Chen
[email protected]If you only want to check your name, use:
git config user.nameTo check your email, use:
git config user.emailIf you make a mistake, there is no need to remove the old setting first. Simply run the command again with the correct value:
git config --global user.name "New Name"The new value will replace the old one.
Understanding the Shape of a Git Command
As you continue through this tutorial, you will often see commands such as:
git statusgit clonegit commitThey all follow the same basic pattern:
git + actionFor example, git status asks Git to show the current repository status, git clone copies an existing repository, and git commit creates a new commit. There is no need to memorize all of these commands now. We will introduce each one when it becomes useful.
Practice
In your terminal, check the Git version, configure a name and email, then query both values. Write the commands in order below. You may use a sample email; do not enter private information.