How to Install Git on Fedora Linux

Git is the distributed version control system that underpins modern software development. Whether you are tracking changes in a personal project, collaborating on open-source software, or managing enterprise codebases, Git provides the foundation for branching, merging, and maintaining a complete history of your work. Unlike centralized systems, Git stores a full repository copy locally, allowing you to commit changes, create branches, and review history without network access.

By the end of this guide, you will have a working Git installation on Fedora, configured with your identity for commits, and ready to clone repositories, track changes, and push updates to remote services like GitHub or GitLab. You will also learn how to compile Git from source if you need a specific version unavailable in Fedora’s repositories.

Update Fedora Before Installing Git

Before installing Git, update your system to ensure all existing packages are current. This step helps avoid dependency conflicts during installation.

sudo dnf upgrade --refresh

Choose Your Git Installation Method

Install Git with DNF (Recommended)

Fedora maintains an up-to-date version of Git in its official repositories. As a result, installation through DNF is straightforward and recommended for most users. To install Git, execute the following command:

sudo dnf install git

Once installation completes, verify that Git is available on your system:

git --version

You should see output showing the installed version:

git version 2.52.0

Install Git from Source Code

Alternatively, compiling from source is useful when you need a specific Git version unavailable through DNF or want to build Git with custom compile-time options.

First, visit the official Git releases page to identify the latest stable version. After selecting your desired version, download the source code using the wget command:

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

The version numbers in this guide (v2.52.0) are examples current at the time of writing. Always check the official releases page for the latest stable version and substitute accordingly in all commands below.

Next, extract the source code with the tar command:

tar -xzf v2.52.0.tar.gz

Then, navigate to the extracted source directory:

cd git-2.52.0

Before compiling, install the Development Tools group. This package includes GCC, make, and other essential build utilities required for compiling software from source:

sudo dnf groupinstall "Development Tools"

If you regularly compile software from source, familiarize yourself with build tools like CMake on Fedora for managing complex build configurations.

However, the Development Tools group does not include all libraries Git requires. Therefore, install the additional build dependencies:

sudo dnf install libcurl-devel expat-devel openssl-devel zlib-devel gettext-devel perl-ExtUtils-MakeMaker

With all prerequisites in place, compile Git by executing the make command:

make prefix=/usr/local all

After compilation finishes, install Git to your system:

sudo make prefix=/usr/local install

Finally, verify the installation by checking the Git version:

git --version

You should see output confirming the installed version:

git version 2.52.0

Configure Git and Learn Essential Commands

With Git installed, configure your identity and learn the commands you will use daily. This section covers initial setup, repository creation, and basic workflow commands. For comprehensive coverage of advanced features, refer to the official Git documentation.

If you plan to use Git with remote services like GitHub, GitLab, or self-hosted repositories, consider installing GitHub Desktop on Fedora for a graphical workflow or Visual Studio Code on Fedora for integrated version control within your editor.

Set Your Git Identity

After installation, configure your name and email address. Git embeds this information in every commit you create, identifying you as the author. Importantly, these settings apply globally to all repositories on your system unless overridden per repository.

First, set your name globally:

git config --global user.name "YOUR NAME"

Next, configure your email address. If you prefer privacy, consider using a no-reply address or pseudonymous email:

git config --global user.email "YOUR EMAIL"

Create Your First Repository

To start tracking a project, first create a directory:

mkdir -p example-directory

Then, navigate into the directory:

cd example-directory

Now, initialize it as a Git repository:

git init

You should see confirmation output:

Initialized empty Git repository in /home/user/example-directory/.git/

This command creates a hidden .git directory that stores the repository configuration, commit history, and tracking metadata. To explore its contents, run:

ls .git

You should see the repository structure:

branches  config  description  HEAD  hooks  info  objects  refs

Verify Your Git Configuration

To confirm your Git configuration settings, run the config list command:

git config --list

You should see your configured settings:

user.name=Your Name
user.email=your.email@example.com

Additionally, Git stores global configuration in the ~/.gitconfig file. You can review its contents directly:

cat ~/.gitconfig

Cache Your Git Credentials

When pushing to or pulling from remote repositories over HTTPS, Git prompts for your username and password each time. To avoid this, the credential helper caches your credentials in memory temporarily, which eliminates repetitive authentication prompts during a work session:

git config --global credential.helper cache

For better security, consider caching credentials for a limited time only. For instance, if you plan to work with Git for a few hours today but not again for several weeks, set a 5-hour timeout:

git config --global credential.helper "cache --timeout=18000"

Consequently, after 5 hours, the credentials will be automatically cleared from memory.

Check Repository Status

To view the status of a Git repository, use the following command:

git status

In a freshly initialized repository with no files, you will see:

On branch main

No commits yet

nothing to commit (create/copy files and use "git add" to track)

Link to a Remote Repository

To collaborate with others or back up your work, link your local repository to a remote service like GitHub, GitLab, or a self-hosted server:

git remote add origin remote-repository-link

For secure authentication, consider configuring SSH on Fedora and using SSH URLs (git@github.com:user/repo.git) instead of HTTPS. As a result, SSH key authentication eliminates password prompts while providing stronger security.

Stage and Commit Changes

Before committing changes, you must stage the files you want to include. Staging allows you to selectively choose which changes go into each commit:

git add filename.txt

Alternatively, stage all modified files at once:

git add .

Once your changes are staged, commit them to the repository history with a descriptive message:

git commit -m "Add new feature for user authentication"

Always write clear, concise commit messages that describe what changed and why. Good messages help you and collaborators understand the project history later.

Push Changes to Remote

After committing locally, push your changes to the remote repository to synchronize with the server:

git push origin main

Modern Git versions and hosting services like GitHub use main as the default branch name instead of master. If working with older repositories, replace main with master in push and pull commands.

Pull Changes from Remote

Similarly, to fetch changes from the remote repository and merge them into your local branch, use:

git pull origin main

Manage Git Installation

Update Git

When installed via DNF, Git updates arrive with your standard system packages. Since Fedora typically provides Git updates within days of upstream releases, simply run the following command to update all packages:

sudo dnf upgrade --refresh

However, for source-compiled installations, you must repeat the download, extraction, and compilation steps with the newer version. The installation process will overwrite the previous binaries automatically.

Remove Git

Remove DNF-Installed Git

If you installed Git using the DNF package manager, uninstalling it is straightforward. Execute the following command:

sudo dnf remove git

DNF will then locate and uninstall Git along with its associated files from your Fedora system.

Remove Source-Compiled Git

In contrast, source-compiled Git requires manual removal since no uninstaller is provided. Follow these steps:

Step 1: Locate the Installation Directory

If you followed the standard installation process, Git binaries are likely in /usr/local/bin. Verify the location:

which git

For source-compiled installations, you should see:

/usr/local/bin/git

Step 2: Remove the Binaries

After confirming the location, manually remove the Git binaries:

sudo rm -f /usr/local/bin/git
sudo rm -f /usr/local/bin/git-*

Step 3: Remove Associated Directories

Additionally, remove the other directories associated with Git:

sudo rm -rf /usr/local/libexec/git-core
sudo rm -rf /usr/local/share/git-core
sudo rm -rf /usr/local/share/man/man1/git*
sudo rm -rf /usr/local/share/man/man5/git*
sudo rm -rf /usr/local/share/man/man7/git*

After completing these steps, verify that Git has been fully removed:

git --version

If Git has been removed, this command should return an error:

bash: git: command not found

Remove Git User Configuration

Optionally, if you want to completely remove your Git configuration and stored credentials, delete the following files from your home directory:

rm ~/.gitconfig
rm ~/.git-credentials

Removing ~/.gitconfig deletes your global Git settings (name, email, aliases, and preferences). Removing ~/.git-credentials deletes stored authentication tokens. Back up these files before deletion if you need to preserve your configuration.

Conclusion

You now have Git installed on Fedora through either the DNF package manager or source compilation. With your user credentials configured, you can clone repositories, track file changes with commits, create branches for parallel development, and synchronize work with remote services. For graphical workflows, pair Git with tools like GitHub Desktop or integrate it into Visual Studio Code. As you build projects, explore advanced Git features like rebasing, stashing, and cherry-picking to refine your version control workflow.

Useful and Relevant Links

Here are some valuable links related to using Git:

  • Git Official Website: Visit the official Git website for information about the version control system, its features, and download options.
  • Git Releases on GitHub: Explore the latest releases of Git on GitHub to download the most recent versions and view release notes.
  • Git Documentation: Access comprehensive documentation for detailed guides on using and configuring Git.
  • Git Community: Join the Git community to connect with other users, participate in discussions, and find support.
  • Fedora Git Quick Reference: Check out the Fedora Git quick reference guide for tips and instructions on using Git with Fedora.

Leave a Comment