How to Install Git on Ubuntu

How to Install Git on Ubuntu

Project work often means keeping track of changes to files as they develop. Git records those changes in a repository, and Ubuntu’s APT package manager installs Git from configured software sources.

I’ll walk you through installing Git on Ubuntu and preparing a project repository.

TL;DR

Install Git from Ubuntu’s APT repositories, check that the command is available, then set your commit identity before initializing a project.

sudo apt update
sudo apt install git
git --version
  • APT installs the git package provided for your Ubuntu release.
  • Configure a name and email for commit metadata.
  • Run git init inside the project folder to start its history.

What Is Git on Ubuntu?

Git is a distributed version control system that records changes to files in a repository. Ubuntu uses APT, its package manager, to install and update software from configured sources.

Start with a local repository because Git records project history without a hosting account. Add a remote such as GitHub or GitLab when you want to share that history.

How to Install Git on Ubuntu Step by Step

Refresh APT’s package index before installing Git because the installer uses that list to find package versions.

Step 1: Refresh the APT package list

APT’s package list is a local index of available package versions.

sudo apt update

Run this before installing Git. If APT reports repository errors, resolve them before continuing.

Step 2: Install the Git package

Install the package named git. APT resolves its dependencies and asks you to approve the package changes.

sudo apt install git

The Git project documents apt-based installation for Debian and Ubuntu systems.

Step 3: Check that Git is available

Print the installed version to confirm that your shell can find the Git executable.

git --version

A version string confirms the shell can find Git. Its value depends on the Ubuntu release and package sources. If the shell reports that the command is missing, check that the installation completed and open a fresh terminal.

Step 4: Set the author name and email

Git saves this name and email with each commit as author information. Use the global setting for your account, or configure a different identity locally inside one repository.

git config --global user.name "Your Name"
git config --global user.email "[email protected]"
git config --global --list

Replace the example values with the details you want on your commits. For a project-specific identity, run the commands from that repository and use --local instead of --global.

Step 5: Initialize a project repository

Change to the project directory first so Git creates its metadata in the intended location. For a new project, create its folder first.

mkdir my-project
cd my-project
git init

The .git directory holds the repository data. After adding files, use git status to review the project state before your first commit.

Common Git Installation Issues

For routine use, keep to Ubuntu’s package. Add the Git Core PPA only when you need a newer upstream release, because it adds another software source.

SituationWhat to do
APT cannot locate gitCheck that Ubuntu package sources are enabled, then run apt update again.
You need a newer upstream releaseUse Git’s current PPA instructions and review the added source before installing.
You are looking for Git BashUbuntu uses its regular terminal shell with the Git client installed through APT.
You prefer a graphical clientChoose a separate Git interface that fits your workflow.

For package discovery, see how to search packages with APT and the guide to package management on Linux.

Conclusion

Install Git on Ubuntu, confirm the shell can find it, and configure the author details Git will attach to commits. Initializing from the project directory keeps its history with the right files.

For more detail, read the Git installation documentation and Ubuntu’s guide to Git version control. The LinuxForDevices latest Git installation guide covers the upstream route.

FAQ

These answers cover installing the package and checking the command.

How do I install Git on Ubuntu?

Run sudo apt update, then sudo apt install git. APT installs the Git package from the repositories configured for your Ubuntu release.

How can I check whether Git is installed?

Run git –version. If Git is available in your shell, it prints the installed version.

Does Ubuntu install Git Bash?

No. Git Bash is associated with Git for Windows. Ubuntu provides the Git command-line client through its package manager and uses the installed terminal shell.