DEV Community

Cover image for How to Set Up Git?
Syed Sohan
Syed Sohan

Posted on • Originally published at syedsohan.hashnode.dev

How to Set Up Git?

Hello πŸ‘‹ good people. In this blog post, we will learn how to set up Git on your local computer. Because Git is responsible for everything GitHub-related that happens locally on your computer.

Those who don't know what Git & GitHub is, kindly read this post to know about Git & GitHub Introduction to Git & GitHub for Beginners.

Table of contents

  1. Download and Install Git

  2. Set your Git username Globally

  3. Set your Git username for a Single Repository

  4. Set your email globally

  5. Set your email for a single repository

Download and Install Git

To download & install Git just go to this following page and download Git for your preferable OS (macOS, Windows, Linux/Unix).

Git-Logo-1788C.png

Set your Git username Globally

You can change the name that is associated with your Git commits using the git config command. The new name you set will be visible in any future commits you push to GitHub from the command line.

  • Open Git Bash.

  • Set your Git username

$ git config --global user.name "John Doe"

Enter fullscreen mode Exit fullscreen mode
  • Recheck that you've given the right username
$ git config --global user.name
> John Doe
Enter fullscreen mode Exit fullscreen mode

Set your Git username for a Single Repository

  • Open Git Bash.

  • Change the current working directory to the local repository where you want to configure the name that is associated with your Git commits.

  • Set your Git username

$ git config user.name "John Doe"

Enter fullscreen mode Exit fullscreen mode
  • Recheck that you've given the right username
$ git config user.name
> John Doe
Enter fullscreen mode Exit fullscreen mode

Set your email globally

  • Open Git Bash.

  • Set your email address in Git. You can use your GitHub-provided no-reply (if you change your email public to private in GitHub) email address or any email address.

$ git config --global user.email "email@example.com"
Enter fullscreen mode Exit fullscreen mode
  • Recheck that you've given the right email
$ git config --global user.email
> email@example.com
Enter fullscreen mode Exit fullscreen mode

Set your email for a single repository

  • Open Git Bash.

  • Change the current working directory to the local repository where you want to configure the email address that is associated with your Git commits.

  • Set your email address in Git. You can use your GitHub-provided no-reply (if you change your email public to private in GitHub) email address or any email address.

git config user.email "email@example.com"

Enter fullscreen mode Exit fullscreen mode
  • Recheck that you've given the right email
$ git config user.email
> email@example.com
Enter fullscreen mode Exit fullscreen mode

Thanks for reading this post. Stay tuned for more.

You can find me here also.

Buy Me A Coffee

Top comments (2)

Collapse
 
peter279k profile image
peter279k

Another tip is about setting the favorite editor for writing commits.
It can use following code snippets to complete this:

peterli@peterli-Virtual-Machine:~$ git config --global core.editor vim
Enter fullscreen mode Exit fullscreen mode

As we can see, it can use the above command to set favorite editor for writing commits globally. And we can also use the following command to set editor for the single repository:

peterli@peterli-Virtual-Machine:~$ git config core.editor vim
peterli@peterli-Virtual-Machine:~$
Enter fullscreen mode Exit fullscreen mode

We can use the git config --list to get all setting lists:

peterli@peterli-Virtual-Machine:~$ git config --list
user.email=peter279k@gmail.com
user.name=Peter
core.editor=vim
Enter fullscreen mode Exit fullscreen mode
Collapse
 
syedsohan profile image
Syed Sohan

Thanks for sharing.