How to Install Git on Linux Mint

Git tracks every change you make to code, configuration files, or documentation, creating a complete history you can navigate, compare, and restore at any point. Whether you need to roll back a breaking change in your web application, collaborate with contributors on a shared repository, or maintain multiple feature branches for a personal project, Git gives you the branching, merging, and commit workflows to manage updates without losing work or overwriting teammate contributions.

Most Linux Mint users will install Git from the default repository for system-integrated updates and long-term stability. Developers who need the latest features (such as improved performance or new commands) can add the Ubuntu Git Maintainers PPA for current stable releases. Advanced users building custom Git binaries or testing patches may compile from source for complete control over build options and installation paths. Additionally, you will configure your identity (name and email), verify the installation, and have a production-ready Git setup for local repositories and remote hosting platforms like GitHub or GitLab.

Update Linux Mint Before Git Installation

Before starting the installation process, update your Linux Mint system to ensure all packages are current and avoid conflicts during the installation. Open the Terminal application by pressing Ctrl+Alt+T or searching for “Terminal” in the application menu.

Run the following command to update the package lists:

sudo apt update

Then upgrade any outdated packages by running the following:

sudo apt upgrade

Method 1: Install Git with APT

APT offers two approaches: installing from the default Linux Mint repository or adding a third-party PPA for newer versions. Most users should start with the default repository, which provides a stable Git version tested against your system libraries and integrated with automatic security updates.

If you prioritize security and system stability, the default Linux Mint repository is the best choice. These packages receive timely security patches through standard system updates. However, PPA versions may lag behind on security fixes, and source-compiled installations require you to manually track new releases and recompile when updates are available. Only consider the PPA or source methods if you specifically need features from newer Git releases that are not available in the default repository version.

Install Git from the Default Repository

The default Linux Mint repository includes a stable Git version that receives security updates. This method suits most users who do not need the absolute latest features.

First, check if Git is already installed:

git --version

When Git exists on your system, the command returns output similar to:

git version 2.43.0

Without Git installed, the terminal displays an error message:

Command 'git' not found, but can be installed with:

sudo apt install git

Install Git with the following command:

sudo apt install git

The installation will download and configure Git. Once complete, you will see output confirming the package installation:

Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following NEW packages will be installed:
  git
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 3,910 kB of archives.
After this operation, 26.1 MB of additional disk space will be used.
Get:1 http://archive.ubuntu.com/ubuntu noble/main amd64 git amd64 1:2.43.0-1ubuntu7 [3,910 kB]
Fetched 3,910 kB in 1s (3,200 kB/s)
Selecting previously unselected package git.
Preparing to unpack .../git_1%3a2.43.0-1ubuntu7_amd64.deb ...
Unpacking git (1:2.43.0-1ubuntu7) ...
Setting up git (1:2.43.0-1ubuntu7) ...
Processing triggers for man-db (2.11.2-2) ...

After installation completes, verify Git is working:

git --version

You should see output confirming the installed version:

git version 2.43.0

Install Git from the Ubuntu Git Maintainers PPA

For users who prefer the latest stable version of Git, the Ubuntu Git Maintainers PPA provides newer releases than the default repository. Linux Mint builds on Ubuntu LTS, making this PPA fully compatible with your system.

Import the Stable Branch PPA

Add the stable branch of the Ubuntu Git Maintainers PPA by running:

sudo add-apt-repository ppa:git-core/ppa -y

Import the Release Candidate Branch PPA (Optional)

Alternatively, if you want to test upcoming features, you can add the release candidate branch, which contains pre-release versions for testing. Most users should stick with the stable branch above, but you can add both if you want to test upcoming features.

Add the release candidate branch by running:

sudo add-apt-repository ppa:git-core/candidate -y

After importing either PPA, refresh the package lists and install Git:

sudo apt update

Next, check the available Git versions to confirm you successfully added the PPA:

apt-cache policy git

This command displays the available Git versions from configured repositories. You should see output similar to:

git:
  Installed: (none)
  Candidate: 1:2.52.0-0ppa1~ubuntu24.04.1
  Version table:
     1:2.52.0-0ppa1~ubuntu24.04.1 500
        500 https://ppa.launchpadcontent.net/git-core/ppa/ubuntu noble/main amd64 Packages
     1:2.43.0-1ubuntu7 500
        500 http://archive.ubuntu.com/ubuntu noble/main amd64 Packages

The PPA version (2.52.0 in this example) should appear as the candidate, confirming you successfully added the repository.

Now install Git using the following command:

sudo apt install git -y

This command works for both users with and without Git installed.

Verify the installation by checking the Git version:

git --version

You should see the newer PPA version:

git version 2.52.0

Method 2: Install Git via Source Archive

Compiling Git from source gives you access to the absolute latest version and lets you customize compile-time options. This method requires more steps but is useful when you need features not yet available in packaged releases.

Install Git Build Dependencies

Before compiling Git, you need to install the necessary build dependencies. Run the following command to install them:

sudo apt install make libssl-dev libghc-zlib-dev libcurl4-gnutls-dev libexpat1-dev gettext unzip -y

Download Git Source Code

Visit the Git tags page for the latest stable release. At the time of writing, the current stable version is v2.52.0. Use the wget command to download the desired archive, replacing {version} with the version number (for example, v2.52.0):

wget https://github.com/git/git/archive/refs/tags/v2.52.0.zip

Alternatively, you can download the latest development version (master) with the following command:

wget https://github.com/git/git/archive/refs/heads/master.zip -O git.zip

The master branch contains development code that may be unstable or have bugs. For production use, download a tagged release instead.

Extract and Compile Git Source Code

Once the download completes, extract the archive using the unzip command:

unzip v2.52.0.zip

Then navigate into the extracted directory:

cd git-2.52.0

Now compile Git using the make command. The prefix=/usr/local option specifies where the installation will place Git:

sudo make prefix=/usr/local all

This compiles all Git components. Once compilation finishes, install Git to your system:

sudo make prefix=/usr/local install

Git now resides in /usr/local/bin, which takes priority over /usr/bin in your system PATH. As a result, the system will use your compiled version instead of any APT-installed Git package. Verify the installation:

git --version

You should see the version you compiled:

git version 2.52.0

Configure Git Identity

Before using Git, configure your identity. Git attaches this information to every commit you make, which collaboration and contribution tracking require. Furthermore, this identity configuration matters whether you manage personal projects, contribute to open-source repositories, or work with development tools like GCC for compiling software on Linux Mint or language environments such as Rust and PHP.

Set your name:

git config --global user.name "Your Name"

Then set your email address (use the same email you use for GitHub, GitLab, or other hosting services if you plan to push code):

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

Verify your configuration:

git config --list

You should see your configured values along with other Git settings:

user.name=Your Name
user.email=your.email@example.com
core.editor=nano
core.repositoryformatversion=0
core.filemode=true
core.bare=false
core.logallrefupdates=true

Git stores these settings in ~/.gitconfig and applies them to all repositories on your system. Additionally, you can override them per-repository by omitting the --global flag when inside a specific project directory.

Troubleshooting Common Git Issues

This section covers common issues you may encounter when using Git on Linux Mint and provides clear solutions with verification steps.

Permission Denied When Pushing to Remote Repository

If you cannot push commits to GitHub or GitLab, you will see an authentication error:

git@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

This occurs when Git cannot authenticate with the remote server because you have not configured an SSH key. To resolve this, generate an SSH key pair and add the public key to your hosting service:

ssh-keygen -t ed25519 -C "your.email@example.com"

Press Enter to accept the default file location and optionally set a passphrase. Next, display your public key:

cat ~/.ssh/id_ed25519.pub

Copy the output and add it to your GitHub or GitLab account under SSH keys in account settings. Then test the connection:

ssh -T git@github.com

A successful connection shows:

Hi username! You've successfully authenticated, but GitHub does not provide shell access.

Git Commands Use Wrong Version After Multiple Installations

If you installed Git from both APT and source, the wrong version may run. Check which Git binary is active:

which git

The output shows the path Git is using:

/usr/local/bin/git

Source-compiled installations in /usr/local/bin take priority over APT packages in /usr/bin. However, if you want to use the APT version, remove the source installation as described in the Remove Git section above, then verify:

which git && git --version

Confirm the path changed and the version matches your expectations.

Fatal Error: Not a Git Repository

Running Git commands outside an initialized repository produces this error:

fatal: not a git repository (or any of the parent directories): .git

This means you are not in a directory tracked by Git. Either navigate to an existing repository or initialize a new one:

git init

Verify Git created the repository:

ls -la | grep .git

You should see a .git directory confirming the repository exists.

Basic Git Workflow Commands

After installing and configuring Git, these fundamental commands let you track changes, create commits, and manage branches in your repositories.

Initialize or Clone a Repository

Create a new local repository in the current directory:

git init

Alternatively, if working with an existing project, clone an existing remote repository:

git clone https://github.com/username/repository.git

This creates a local copy of the repository with full history and tracking configured automatically.

Check Repository Status

View which files changed, which you have staged, and which branch you are on:

git status

This command shows untracked files, modified files, and staged changes ready for commit.

Stage and Commit Changes

Add specific files to the staging area:

git add filename.txt

Or stage all changes in the current directory:

git add .

Create a commit with a descriptive message:

git commit -m "Add feature X to improve performance"

Create and Switch Branches

Create a new branch for feature development:

git branch feature-branch

Then switch to the new branch:

git checkout feature-branch

Or create and switch in one command:

git checkout -b feature-branch

Push Changes to Remote Repository

After committing locally, push changes to the remote repository:

git push origin main

Replace main with your branch name. For example, for new branches, use:

git push -u origin feature-branch

The -u flag sets the upstream tracking so future pushes only require git push.

Additional Commands and Tips for Git

Update Git

For APT installations (default repository or PPA), Git updates arrive through standard system upgrades:

sudo apt update && sudo apt upgrade

However, if you compiled Git from source, download the new version, recompile, and run sudo make prefix=/usr/local install again. The new binary will replace the existing one.

Remove Git

To uninstall Git, the process depends on your installation method.

For installations from the default repository:

sudo apt remove git

For users who installed Git from the PPA, first remove the package, then remove the repository:

sudo apt remove git

Then remove the PPA repositories:

sudo add-apt-repository --remove ppa:git-core/ppa -y
sudo add-apt-repository --remove ppa:git-core/candidate -y

For source-compiled installations, remove the Git files from /usr/local:

sudo rm -rf /usr/local/bin/git* /usr/local/share/git-core /usr/local/libexec/git-core

If you installed both a source-compiled version and an APT package, the source version in /usr/local/bin takes precedence. Remove the source installation first, then verify which Git version remains active by running which git and git --version. This will show whether the system is now using the APT-installed version from /usr/bin or if Git has been completely removed.

Conclusion

You now have a production-ready Git installation on Linux Mint with identity configuration, SSH authentication for remote repositories, and knowledge of core workflow commands including initialization, staging, committing, branching, and pushing changes. Whether you chose the stable default repository, the latest PPA version, or a custom source build, you can manage code history, collaborate on shared projects, and resolve common issues like authentication failures or version conflicts. For a graphical interface, consider installing GitHub Desktop on Linux Mint. Developers working with code editors may also want to set up VS Code or VSCodium, both of which integrate directly with Git for inline diffs, staging, and branch management. If you are building development environments, you might also explore Android Studio on Linux Mint for mobile app version control workflows.

Leave a Comment