Configuring Git on the command line

When it comes to using Git and GitHub one of the first things we need to do is configure our user identity on the command line. This means setting up our name and email address, so that every time we make a commit, it includes our signature.

deco-blob-1 decoration
graphical divider

 

Configuring Git on the command line

When it comes to using Git and GitHub one of the first things we need to do is configure our user identity on the command line. This means setting up our name and email address, so that every time we make a commit, it includes our signature.

To do this, we use the command "git config --global user.name" and "git config --global user.email", followed by our name and email address in quotation marks.

Once we've configured our user identity, we can verify that it worked by checking the ".gitconfig" file on our computer. If we don't have this file, it means our Git config isn't set up properly, so we need to make sure we have our username and email address set up correctly.

By aligning our email address with the one we used to sign up for GitHub, GitLab, or Bitbucket, we can ensure that our commits are properly attributed to us.

Key Takeaways
  • Configuring our user identity is an important first step in using Git and GitHub.
  • We can set up our name and email address using the "git config" command.
  • By aligning our email address with our Git hosting service, we can ensure proper attribution for our commits.
Configuring Git on Command Line

To use Git and GitHub from our command line we first need to configure it. Without configuration, Git won't know who we are, what we do, or anything about us. Therefore, we need to configure two things: our name and our email address.

To do this, we type git config --global user.name "Your Name" to configure our name. Replace "Your Name" with your actual name.

Then, we type git config --global user.email "[email protected]" to configure our email address. Replace "[email protected]" with your actual email address.

“The email address should ideally match with our GitHub email address. While it's not necessary, it's a better way of doing things if our email addresses all match.”
– CTO, UpLinkd Group

Make sure to use the exact same email address that you signed up for on GitHub, GitLab, or Bitbucket.

To verify that the configuration worked, we can type cat ~/.gitconfig in our command line. This will show us the contents of our Git configuration file. We should see our user name and email address listed there.

If we don't have this file, it means our Git configuration is not set up. Therefore, we need to make sure that we have our user name and email address set up, and that we have a Git configuration file on our computer.

Once we have our Git configuration set up, we can move on to the next lesson, where we'll talk about adding an SSH key.

Setting Up User Identity

When working with Git or GitHub from our command line, it's essential to configure our user identity. Without this information, Git doesn't know who we are, what we do, or how to sign our commits. In this section, we'll go over how to set up our user name and email address.

Entering User Name

To configure our user name, we'll use the git config command with the --global flag. Open your terminal and type the following command:

$ git config --global user.name "Your Name"

Replace "Your Name" with your actual name. This is the name that will appear as the author of your commits.

Entering User Email

Next, we'll set up our email address. This is the email address that should match the one you used to sign up for Git, GitHub, or any other version control platform you're using. To configure your email address type the following command:

$ git config --global user.email "[email protected]"

Replace "[email protected]" with your actual email address. This email address will be associated with your commits and will allow other users to contact you if necessary.

To verify that your user identity is set up correctly, you can type the following command:

$ cat ~/.gitconfig

This will display your user name and email address in the terminal.

That's it! With your user name and email address configured, you're ready to start using Git and GitHub from your command line. In the next section, we'll go over how to add an SSH key for secure authentication.

Verifying Configuration

Checking Git Config File

Now that we have configured our name and email address, we need to verify that our configuration worked correctly. We can check this by typing cat ~/.gitconfig in our command line. This command will display the contents of the Git config file.

If the configuration was successful, we should see our name and email address listed under the [user] section. If we do not see this information, we need to double-check that we entered our name and email address correctly when we configured Git.

Validating User Name and Email

It is important to ensure that our name and email address match the information we used when we signed up for GitHub, GitLab, or Bitbucket. This is because every time we make a commit, Git will use this information to associate the commit with our account.

To validate our user name and email address, we can use the git log command. This command will display a list of all the commits we have made, along with the author's name and email address.

If our name and email address are correct we should see them listed next to each commit. If we see a different name or email address we need to update our Git configuration to match our account information.

Verifying our Git configuration is an important step in setting up our development environment. By checking the Git config file and validating our user name and email address we can ensure that our commits are properly associated with our account.

Aligning Email Addresses

To ensure that our commits are properly attributed it's important to align our email address with the email address associated with our GitHub, GitLab, or Bitbucket account. This can be done by simply setting our Git configuration email address to match the email address associated with our account.

To do this we can use the git config --global user.email command followed by our email address in quotations. For example, if our GitHub email address is [email protected], we would enter the following command:

$ git config --global user.email "[email protected]"

It's important to note that the email address must match the email address associated with our account exactly. If it does not, our commits may not be properly attributed.

We can verify that our email address has been properly aligned with our account by using the cat ~/.gitconfig command to view our Git configuration file. If our email address is listed under the [user] section, we have successfully aligned our email address.

“Aligning our email address with our GitHub, GitLab, or Bitbucket account is a simple but important step in ensuring that our commits are properly attributed.”
– CTO, UpLinkd Group

By setting our Git configuration email address to match the email address associated with our account, we can avoid any potential issues with attribution and ensure that our contributions are accurately recorded.

Adding SSH Key

Now that we have configured our name and email address, we need to add an SSH key to our GitHub account. This will allow us to securely communicate with GitHub without having to enter our username and password every time.

To add an SSH key, we need to follow a few simple steps:

  1. Open the terminal on your computer and type ssh-keygen -t rsa -b 4096 -C "[email protected]". This will generate a new SSH key.
  2. When prompted to enter a file name, simply press Enter to accept the default file name and location.
  3. You will then be prompted to enter a passphrase. This is an optional security measure, but we highly recommend using one for added security.
  4. Once the key is generated, type eval "$(ssh-agent -s)" to start the SSH agent.
  5. Next, type ssh-add ~/.ssh/id_rsa to add the key to the SSH agent.
  6. Finally, copy the SSH key to your clipboard by typing pbcopy < ~/.ssh/id_rsa.pub. Note that this command is specific to Mac computers. If you are using a different operating system, you may need to use a different command to copy the key to your clipboard.
  7. Log in to your GitHub account and navigate to Settings > SSH and GPG keys.
  8. Click on the "New SSH key" button and paste the key into the "Key" field.
  9. Give the key a descriptive title and click "Add SSH key".

That's it! You have now added an SSH key to your GitHub account, which will allow you to securely communicate with GitHub without having to enter your username and password every time.