Git - Install

Git - Install

Installation of Git

Git is a powerful distributed version control system that allows developers to track changes, collaborate, and manage source code efficiently. Before using Git, it must be properly installed on your system. This guide covers step-by-step instructions for installing Git on Windows, macOS, and various Linux distributions, as well as verifying the installation and setting up the Git environment. 

Prerequisites

  • Basic understanding of the command-line interface
  • Administrator access on your system
  • Internet connection to download Git

Installing Git on Windows

Method 1: Using Git for Windows Installer

  1. Navigate to the official Git website: https://git-scm.com
  2. Click on "Download for Windows".
  3. Once downloaded, run the installer.

During installation, you will encounter several options. Below are the most important ones and recommended settings:

  • Adjusting your PATH environment: Select "Git from the command line and also from 3rd-party software".
  • Choosing HTTPS transport backend: Select "Use the OpenSSL library".
  • Configuring the line ending conversions: Choose "Checkout Windows-style, commit Unix-style line endings".

Verifying Installation

git --version

If installed correctly, this will return the Git version number, such as:

git version 2.43.0.windows.1

Using Git Bash

Along with Git, the installer also installs Git Bash, a terminal emulator for running Git commands.

# Launch Git Bash and type:
git --help

Installing Git on macOS

Method 1: Using Homebrew

If Homebrew is not installed, install it first:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

Then install Git:

brew install git

Method 2: Using Xcode Command Line Tools

xcode-select --install

This command prompts the installation of the Apple Developer tools which include Git.

Method 3: Download Git from Source

  1. Visit https://git-scm.com/download/mac
  2. Download the binary installer
  3. Run the installer and follow the GUI wizard

Verifying Installation

git --version

Expected output:

git version 2.43.0

Installing Git on Linux

Method 1: Using Package Managers

Debian/Ubuntu

sudo apt update
sudo apt install git

Red Hat/CentOS/Fedora

sudo dnf install git

Arch Linux

sudo pacman -S git

Verifying Installation

git --version

Method 2: Building Git from Source

  1. Install dependencies:
sudo apt install make libssl-dev libghc-zlib-dev libcurl4-gnutls-dev libexpat1-dev gettext unzip
  1. Download Git source:
wget https://github.com/git/git/archive/refs/tags/v2.43.0.zip
unzip v2.43.0.zip
cd git-2.43.0
  1. Build and install:
make prefix=/usr/local all
sudo make prefix=/usr/local install

Check Installed Version

git --version

Post-Installation Configuration

Set Username and Email

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

Check Git Configuration

git config --list

Configuring Git Editor

Set Default Editor

To set Nano as the default editor:

git config --global core.editor "nano"

To set VS Code as the default editor:

git config --global core.editor "code --wait"

Installing Git GUI Clients

GitHub Desktop (Windows/macOS)

  1. Download from: https://desktop.github.com
  2. Install and log in using your GitHub account
  3. Create or clone repositories easily via GUI

Sourcetree (Windows/macOS)

  1. Download from: https://www.sourcetreeapp.com/
  2. Supports Git and Mercurial repositories

GitKraken (Cross-platform)

  1. Download from: https://www.gitkraken.com/
  2. Visual interface for Git flow, branches, commits, and merging

Setting Up SSH Keys for Git

Generate SSH Key

ssh-keygen -t rsa -b 4096 -C "your.email@example.com"

Then add SSH key to the ssh-agent:

eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_rsa

Copy Public Key

cat ~/.ssh/id_rsa.pub

Add Key to GitHub/GitLab

  1. Go to your GitHub account
  2. Navigate to Settings β†’ SSH and GPG keys
  3. Click "New SSH key", paste the key, and save

Test SSH Connection

ssh -T git@github.com

Installing Git on WSL (Windows Subsystem for Linux)

If you are using WSL, you can install Git in your Linux environment as follows:

Ubuntu on WSL

sudo apt update
sudo apt install git

Confirm installation:

git --version

Environment Variables and Git Path

After installation, make sure Git is available globally via PATH.

Check Git Path

where git      # Windows
which git      # macOS/Linux

Add Git to Windows PATH Manually

Control Panel β†’ System β†’ Environment Variables β†’ System Variables β†’ PATH β†’ Edit β†’ Add path to Git `bin` directory (e.g., `C:\Program Files\Git\bin`).

Installing Git in IDEs

Visual Studio Code

VS Code uses system Git by default. If Git is installed, VS Code will detect it. You can run Git commands directly in the integrated terminal or source control tab.

JetBrains IDEs (IntelliJ, PyCharm, etc.)

Go to File β†’ Settings β†’ Version Control β†’ Git β†’ Set Git executable path.

Troubleshooting Git Installation

Command Not Found

git: command not found

Solution: Ensure Git is correctly installed and PATH is configured.

Permission Denied (SSH)

Permission denied (publickey)

Solution: Ensure SSH keys are generated and added to GitHub/GitLab. Run:

ssh-add ~/.ssh/id_rsa

Incorrect Git Version

Old versions of Git may lack features like partial clone, sparse checkout, etc. Upgrade via:

sudo apt install git --only-upgrade     # Debian
brew upgrade git                        # macOS

Installing Git is the first step toward powerful source code management, collaboration, and version control. Whether you're using Windows, macOS, or Linux, Git can be set up quickly using the appropriate tools. Post-install configuration such as user identity, editor preferences, and SSH key setup is essential for effective use. By following the steps outlined above, you’ll be well on your way to working with Git professionally.

After installation, consider exploring further Git topics like repository creation, branching, merging, and remote workflows to become proficient with Git.

Beginner 5 Hours
Git - Install

Installation of Git

Git is a powerful distributed version control system that allows developers to track changes, collaborate, and manage source code efficiently. Before using Git, it must be properly installed on your system. This guide covers step-by-step instructions for installing Git on Windows, macOS, and various Linux distributions, as well as verifying the installation and setting up the Git environment. 

Prerequisites

  • Basic understanding of the command-line interface
  • Administrator access on your system
  • Internet connection to download Git

Installing Git on Windows

Method 1: Using Git for Windows Installer

  1. Navigate to the official Git website: https://git-scm.com
  2. Click on "Download for Windows".
  3. Once downloaded, run the installer.

During installation, you will encounter several options. Below are the most important ones and recommended settings:

  • Adjusting your PATH environment: Select "Git from the command line and also from 3rd-party software".
  • Choosing HTTPS transport backend: Select "Use the OpenSSL library".
  • Configuring the line ending conversions: Choose "Checkout Windows-style, commit Unix-style line endings".

Verifying Installation

git --version

If installed correctly, this will return the Git version number, such as:

git version 2.43.0.windows.1

Using Git Bash

Along with Git, the installer also installs Git Bash, a terminal emulator for running Git commands.

# Launch Git Bash and type: git --help

Installing Git on macOS

Method 1: Using Homebrew

If Homebrew is not installed, install it first:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

Then install Git:

brew install git

Method 2: Using Xcode Command Line Tools

xcode-select --install

This command prompts the installation of the Apple Developer tools which include Git.

Method 3: Download Git from Source

  1. Visit https://git-scm.com/download/mac
  2. Download the binary installer
  3. Run the installer and follow the GUI wizard

Verifying Installation

git --version

Expected output:

git version 2.43.0

Installing Git on Linux

Method 1: Using Package Managers

Debian/Ubuntu

sudo apt update sudo apt install git

Red Hat/CentOS/Fedora

sudo dnf install git

Arch Linux

sudo pacman -S git

Verifying Installation

git --version

Method 2: Building Git from Source

  1. Install dependencies:
sudo apt install make libssl-dev libghc-zlib-dev libcurl4-gnutls-dev libexpat1-dev gettext unzip
  1. Download Git source:
wget https://github.com/git/git/archive/refs/tags/v2.43.0.zip unzip v2.43.0.zip cd git-2.43.0
  1. Build and install:
make prefix=/usr/local all sudo make prefix=/usr/local install

Check Installed Version

git --version

Post-Installation Configuration

Set Username and Email

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

Check Git Configuration

git config --list

Configuring Git Editor

Set Default Editor

To set Nano as the default editor:

git config --global core.editor "nano"

To set VS Code as the default editor:

git config --global core.editor "code --wait"

Installing Git GUI Clients

GitHub Desktop (Windows/macOS)

  1. Download from: https://desktop.github.com
  2. Install and log in using your GitHub account
  3. Create or clone repositories easily via GUI

Sourcetree (Windows/macOS)

  1. Download from: https://www.sourcetreeapp.com/
  2. Supports Git and Mercurial repositories

GitKraken (Cross-platform)

  1. Download from: https://www.gitkraken.com/
  2. Visual interface for Git flow, branches, commits, and merging

Setting Up SSH Keys for Git

Generate SSH Key

ssh-keygen -t rsa -b 4096 -C "your.email@example.com"

Then add SSH key to the ssh-agent:

eval "$(ssh-agent -s)" ssh-add ~/.ssh/id_rsa

Copy Public Key

cat ~/.ssh/id_rsa.pub

Add Key to GitHub/GitLab

  1. Go to your GitHub account
  2. Navigate to Settings → SSH and GPG keys
  3. Click "New SSH key", paste the key, and save

Test SSH Connection

ssh -T git@github.com

Installing Git on WSL (Windows Subsystem for Linux)

If you are using WSL, you can install Git in your Linux environment as follows:

Ubuntu on WSL

sudo apt update sudo apt install git

Confirm installation:

git --version

Environment Variables and Git Path

After installation, make sure Git is available globally via PATH.

Check Git Path

where git # Windows which git # macOS/Linux

Add Git to Windows PATH Manually

Control Panel → System → Environment Variables → System Variables → PATH → Edit → Add path to Git `bin` directory (e.g., `C:\Program Files\Git\bin`).

Installing Git in IDEs

Visual Studio Code

VS Code uses system Git by default. If Git is installed, VS Code will detect it. You can run Git commands directly in the integrated terminal or source control tab.

JetBrains IDEs (IntelliJ, PyCharm, etc.)

Go to File → Settings → Version Control → Git → Set Git executable path.

Troubleshooting Git Installation

Command Not Found

git: command not found

Solution: Ensure Git is correctly installed and PATH is configured.

Permission Denied (SSH)

Permission denied (publickey)

Solution: Ensure SSH keys are generated and added to GitHub/GitLab. Run:

ssh-add ~/.ssh/id_rsa

Incorrect Git Version

Old versions of Git may lack features like partial clone, sparse checkout, etc. Upgrade via:

sudo apt install git --only-upgrade # Debian brew upgrade git # macOS

Installing Git is the first step toward powerful source code management, collaboration, and version control. Whether you're using Windows, macOS, or Linux, Git can be set up quickly using the appropriate tools. Post-install configuration such as user identity, editor preferences, and SSH key setup is essential for effective use. By following the steps outlined above, you’ll be well on your way to working with Git professionally.

After installation, consider exploring further Git topics like repository creation, branching, merging, and remote workflows to become proficient with Git.

Related Tutorials

Frequently Asked Questions for GitHub

Teams use GitHub for version control, code sharing, pull requests, and project management.

SSH allows secure communication with GitHub for pushing and pulling code without passwords.

A release marks a specific version of code, often used for deployments or tagging milestones.

Git is a distributed version control system for tracking changes in source code efficiently.

It shows the current state of the repository, including staged, unstaged, and untracked files.


GitHub Pages hosts static websites directly from a GitHub repository.

Git is a tool; GitHub is a platform using Git for remote code collaboration.

Use git revert <commit> to undo changes by creating a new commit.

git commit saves staged changes to the local repository with a message.


Issues track bugs, tasks, or feature requests, allowing discussion and assignment.

Merging combines changes from different branches into one branch, typically main or master.


git push uploads local repository changes to a remote repository like GitHub.

GitHub Actions automates workflows like building, testing, and deploying code with CI/CD pipelines.

.gitignore specifies files and directories Git should ignore and not track.

git init initializes a new Git repository in your local project directory.

git add stages changes in files for the next commit.

A pull request proposes changes from one branch to another, usually for review and merge.

A branch allows parallel development by creating independent code versions from the main project.

GitHub is a cloud-based platform for hosting and managing Git repositories collaboratively.

The default branch name is usually main, previously known as master.

Cloning downloads a copy of a GitHub repository to your local machine.

git pull fetches and merges changes from a remote repository to your local branch.

A commit records a snapshot of file changes with a message and unique ID.

A repository stores project files, folders, and version history for collaborative development.

A fork creates a personal copy of another user's repository for independent development.


A GitHub milestone is a way to track progress on a specific goal or release by grouping related issues and pull requests.

To merge a pull request, review the proposed changes and click "Merge pull request" to integrate them into the base branch.

GitHub labels are tags that help categorize and prioritize issues and pull requests, making it easier to manage and filter them.​

To create a GitHub issue, navigate to the "Issues" tab of your repository and click "New issue."

After making changes in your forked repository, navigate to the original repository and click "New pull request" to propose your changes.

A merge conflict occurs when GitHub cannot automatically merge changes due to conflicting modifications in the same part of a file.​

To use GitHub Actions, create a YAML file in the .github/workflows directory of your repository to define your workflow.

To resolve a merge conflict, manually edit the conflicting files to combine changes, then commit the resolved files.

A branch in GitHub is a parallel version of a repository, allowing you to work on different features or fixes without affecting the main codebase.​

To add a collaborator, go to your repository's settings, select "Collaborators," and enter the GitHub username of the person you want to add.​

A GitHub Gist is a simple way to share code snippets or text, useful for sharing small pieces of code or notes.

A fork creates a personal copy of someone else's repository, allowing you to propose changes. A clone creates a local copy of a repository on your machine.​

To create a GitHub repository, log in to your GitHub account, click the "+" icon in the top right corner, and select "New repository."

To set up GitHub Pages, navigate to your repository's settings, scroll to the "GitHub Pages" section, and select the source branch.

To create a GitHub Gist, log in to your GitHub account, click the "+" icon, and select "New Gist."

A GitHub organization is a shared account where multiple people can collaborate on repositories, issues, and other GitHub features.​

The GitHub CLI is a command-line interface that allows you to interact with GitHub directly from your terminal, enabling operations like creating issues and pull requests.

o use GitHub Copilot, install the extension in a supported IDE, such as Visual Studio Code, and start typing code to receive suggestions.

To create a GitHub organization, click your profile picture in the top right corner, select "Your organizations," and click "New organization."

GitHub Copilot is an AI-powered code completion tool developed by GitHub in collaboration with OpenAI, providing suggestions as you code.​

GitHub is a web-based platform for version control and collaboration, allowing developers to host and review code, manage projects, and build software together.​

To install the GitHub CLI, download the appropriate version for your operating system from the official GitHub CLI website and follow the installation instructions.

line

Copyrights © 2024 letsupdateskills All rights reserved