How to install and configure Git??

Introduction

In this article, we will discuss how to install and configure Git on your system.

Git is a widely used version control system that is used by developers to manage their code base. It is a powerful tool that allows developers to collaborate on a project, track changes, and maintain version history.

Step1: Download Git

The first step to installing Git is to download it from the official Git website. You can download Git for Windows, Mac, and Linux from https://git-scm.com/downloads.

Step 2: Install Git

Once you have downloaded the Git installer for your operating system, you can begin the installation process. The installation process is different for each operating system, but it is generally straightforward.

Install Git on Windows

On Windows, double-click on the Git installer and follow the on-screen instructions to install Git.

Install Git on Mac

On Mac, double-click on the Git installer package and follow the on-screen instructions to install Git.

Install Git on Linux

Install Git on different Linux distributions, including Ubuntu, Debian, CentOS, and Fedora.

Ubuntu/Debian

1. Open a terminal window by pressing Ctrl + Alt + T or searching for “Terminal” in the applications menu.

2. Update your system’s package list by running the following command:sql

sudo apt-get update

3. Install Git by running the following command:

sudo apt-get install git

4. Verify that Git was installed successfully by running the following command:

git --version 

This should display the version of Git that was installed on your system.

CentOS/Fedora

1. Open a terminal window by pressing Ctrl + Alt + T or searching for “Terminal” in the applications menu.

2. Install Git by running the following command:

sudo dnf install git

3. If you are using CentOS, use the following command instead:

sudo yum install git

4. Verify that Git was installed successfully by running the following command:

git --version

This should display the version of Git that was installed on your system.

Configure Git

Configure Git on Windows

There are two ways in which we can work with our recently installed Git:

  1. Git GUI
  2. Git bash

After installing Git, right-click your mouse on a Windows explorer or where you want to create your project and want to use Git to control the version.

You will see options like this:

install and configure Git

Setting global user name and email: these are identifications that you are working with the project. Commands:

$ git config --global user.name "My Name"
$ git config --global user.email myEmail@example.com

Initializing the git local repository in your computer: open a git bash and execute the command like below:

$  git init

📝Note: You can also use the Windows command line to configure the Git like Mac and Linux OS below.

Configure Git: Mac and Linux

After installing Git, you may want to configure it to suit your needs. This includes setting your name and email address, configuring your text editor, and more. To configure Git, open a terminal window and run the following command:

git config --global <key> <value>

Replace <key> with the configuration option that you want to set, and <value> with the value that you want to assign to it. For example, to set your name and email address, run the following commands:

git config --global user.name "Your Name"
git config --global user.email "your-email@example.com"

This will set your name and email address as the default author information for Git commits.

Configure Git by Updating the .gitconfig File

For most of the users, the above methods of configuring will work. This method is only if you want to update the Git configuration file directly.

Once you have installed Git, the next step is to configure it. Git uses a configuration file called .gitconfig to store its settings. This file is located in your home directory.

📝Note: You can modify this file with your settings using any text editors like vi/vim, nano, etc; in windows, you can simply use notepad.

To open the .gitconfig file, open a terminal window and type the following command:

nano ~/.gitconfig

This will open the .gitconfig file in the nano text editor. You can also use any other text editor that you prefer.

The .gitconfig file contains several sections, each of which is used to configure different aspects of Git. The most important sections are [user], [core], and [color].

[user] section:

The [user] section is used to configure your name and email address. This information is used by Git to identify the author of a commit.

To configure your name and email address, add the following lines to the [user] section of the .gitconfig file:

[user]
name = Your Name
email = your-email@example.com

Replace “Your Name” and “your-email@example.com” with your actual name and email address.

[core] section:

The [core] section is used to configure Git’s core behavior. You can configure Git to use a specific text editor, set the default branch name, and more.

To configure Git’s core behavior, add the following lines to the [core] section of the .gitconfig file:

[core]
editor = nano
autocrlf = input
pager = less -r
defaultBranch = main

📝Note: Replace “nano” with the name of your preferred text editor.

[color] section:

The [color] section is used to configure Git’s color output. You can configure Git to use colors in the output of several commands, such as git status.

To configure Git’s color output, add the following lines to the [color] section of the .gitconfig file:

[color]
ui = auto
status = auto
branch = auto
diff = auto
log = auto