Git Install

Divya Srinivasan

 How to Install Git

You can get Git for free from git-scm.com.

Windows:
  • Download the installer and run it.
  • Click “Next” to go through the default recommended settings.
  • This process installs both Git and Git Bash.
macOS:
  • If you have Homebrew, open Terminal and run:
nginx
brew install git
  • Alternatively, download the .dmg file and drag Git into your Applications folder
Linux:
  • Open your terminal and use your distribution’s package manager.
  • For example, on Ubuntu, type:
arduino
sudo apt-get install git
Once installed, you’ll be able to use Git directly from your terminal or command prompt.

Git Bash

  • Git Bash is a command-line tool for Windows that lets you run Git commands.
  • For a deeper understanding, check out our Bash Tutorial.
  • Once you’ve installed Git, you’ll find Git Bash in your Start menu.
  • It works similarly to the Command Prompt but also supports additional Unix-style commands, such as ls and pwd.

Example:

Your First Command in Git Bash
bash
ls
When you run the ls command, you’ll see something like this:
nginx
Desktop  Documents  Downloads  Pictures
This command displays a list of all files and folders in your current directory, helping you see what’s inside the folder you’re working in.

Verifying Your Installation

After installing Git, you should confirm that it’s working properly. Open your terminal (or Git Bash on Windows) and type:

Example: 

Check Git Version
pgsql
git --version
git version 2.43.0.windows.1
If Git is installed correctly, you’ll see output similar to git version X.Y.Z.
If you encounter an error, try closing and reopening your terminal, or make sure Git has been added to your system’s PATH.

Choosing a Default Editor

When you install Git, it will prompt you to select a default text editor.
This editor is used whenever you need to write messages—such as commit messages.

Example: 

Use VS Code as your default editor
bash
git config --global core.editor "code --wait"
If you’re unsure, you can stick with the default option (Notepad on Windows). You can always change it later.

Example:

Use Notepad as your default editor
bash
git config --global core.editor "notepad"

PATH Environment

Adding Git to your system PATH allows you to run Git commands from any terminal window.
This is strongly recommended for most users during installation.
If you don’t add Git to your PATH, you’ll only be able to use it within Git Bash on Windows or Terminal on macOS and Linux.

Example: 

Check if Git is in your PATH
bash
git --version
git version 2.43.0.windows.1
If this command returns an error, it means Git isn’t in your PATH, and you’ll need to add it manually.

How to Add Git to PATH After Installation

Windows

If you skipped adding Git to PATH during installation, you can do it manually:
Search for “Environment Variables” in the Start menu and open it.
Click “Environment Variables…”.
Under “System variables”, find and select the “Path” variable, then click “Edit”.
Click “New”, and add the following paths (adjust if your install location is different):
C:\Program Files\Git\bin
C:\Program Files\Git\cmd
Click OK to save and close all dialogs.
Restart your terminal to apply the changes.
macOS

If you installed Git with Homebrew, it’s usually added to your PATH automatically.
Otherwise, open Terminal and add this line to your ~/.zshrc (or ~/.bash_profile if you use Bash):
bash
export PATH="/usr/local/bin:$PATH"
Save the file and run:
bash
source ~/.zshrc
or
bash
source ~/.bash_profile
Linux

Most package managers automatically add Git to your PATH.
If not, add this line to your ~/.bashrc or ~/.profile:
bash
export PATH="/usr/bin:$PATH"
Save the file and run:
bash
source ~/.bashrc
or
bash
source ~/.profile
After you’ve added Git to your PATH, open a new terminal window and run:
bash
git --version

Line Endings

Git can automatically handle line endings in text files to avoid issues across different operating systems.
If you’re on Windows, it’s usually recommended to choose:
“Checkout Windows-style, commit Unix-style line endings.”
This setting makes sure files use Windows line endings (CRLF) on your machine, but are saved with Unix line endings (LF) in the repository — helping keep things consistent when collaborating with others.

Updating or Removing Git

To update Git:

Download and run the latest installer from git-scm.com, or
Use your system’s package manager (for example: brew upgrade git on macOS, or sudo apt-get upgrade git on Ubuntu/Linux).
Keeping Git updated ensures you get the newest features and important security patches.

To uninstall Git:

On Windows: Open “Add or Remove Programs” and remove Git from the list.
On macOS/Linux: Use your package manager (for example: brew uninstall git or sudo apt-get remove git).

Troubleshooting Git Installation

If you have trouble installing or using Git, don’t worry!
Here are a few solutions to common problems you might encounter.

Common Installation Issues

"git is not recognized as an internal or external command"
Cause: Git isn’t added to your system’s PATH.
Fix:
Make sure Git is installed.
Restart your terminal.
If it still doesn’t work, add Git’s bin folder (usually C:\Program Files\Git\bin) to your PATH manually.
As a last step, restart your computer.
Permission errors (e.g., “Permission denied”)
Fix:
On Windows, run Git Bash or your terminal as Administrator.
On macOS/Linux, use sudo when necessary.
SSL or HTTPS errors when cloning or pushing
Fix:
Verify your internet connection.
Update Git to the latest version.
Wrong version of Git
Fix:
Check your version with git --version.
If outdated, download and install the latest release from git-scm.com.





























Tags
Our website uses cookies to enhance your experience. Learn More
Accept !

GocourseAI

close
send