How to Install Git on Fedora 39, 38 Linux

This guide will demonstrate how to install Git on Fedora Linux using the command-line terminal, employing either the DNF package manager or by manually downloading and compiling the source for the latest or a custom version of Git to suit your specific requirements.

Git is an essential tool for developers, providing a robust framework for tracking changes in source code during software development. Its distributed version control system facilitates collaborative work, allowing multiple developers to work on a project simultaneously without the risk of conflicting changes. With Git, you can branch out, experiment, and easily merge completed features, enhancing the overall efficiency of development workflows.

Here’s a quick overview of Git’s key features:

  • Efficient handling of large projects
  • Cryptographic authentication of history
  • Flexible branching and merging capabilities
  • Decentralized repository model
  • Supports non-linear development
  • Scalable to large projects and teams
  • Comprehensive backup and restore features
  • Facilitates collaboration and code sharing among developers

Understanding these features will help you appreciate the power and flexibility of Git as you move on to installing it on your Fedora system.

Now, let’s dive into the technical process of installing Git on Fedora Linux.

Update Fedora System Packages Before Git Installation

First, update your system to ensure all existing packages are up to date.

sudo dnf upgrade --refresh

Select Git Installation Method on Fedora

Install Git via DNF Command

Fedora, by default, maintains an up-to-date version of Git. This makes the installation process straightforward. To install Git using the DNF package manager, execute the following command:

sudo dnf install git

Install Git via Source

For those who require a specific version of Git not available through the DNF package manager or wish to install Git with custom configurations, compiling from the source code is the way to go.

Start by visiting the official Git website’s release page. This will allow you to identify the latest stable version or pinpoint a specific version you’re after. Once you’ve chosen your desired version, you can download its source code using the wget command in the terminal:

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

Note: Please do not copy the above command; it is an example only. Git releases new versions frequently, so checking the official website regularly is essential to keep your Git installation up-to-date.

After downloading, extract the source code with the tar command:

tar -xzf v2.42.0.tar.gz

Then, change your directory to the one containing the extracted source:

cd git-2.42.0

Before diving into the compilation, installing the necessary development tools is essential. These tools ensure the presence of most required dependencies:

sudo dnf groupinstall "Development Tools"

However, the standard development tools package might not include a few dependencies. To install these, use:

sudo dnf install libcurl-devel expat-devel

With the prerequisites in place, you can now configure the script. Execute the make command:

make prefix=/usr/local all

To finalize the installation of Git, run:

sudo make prefix=/usr/local install

To verify the successful installation and check the version of Git you’ve installed, use:

git --version
Screenshot showcasing the completed Git installation using the source install method on Fedora Linux.
A visual demonstration of Git’s interface on Fedora Linux post successful source installation.

Basic Git Commands on Fedora

The following parts will cover some typical setups and commands used daily by users of GIT. This is not the complete list; GIT has a vast number of commands and configurations, but newer users may find some of the following examples helpful. I would check out the Git documentation for more information in the long term for users seeking more advanced requirement options or usage.

GIT Add User

After installation, you must set up standard settings such as names and e-mails, mainly around git commit messages. This is pretty straightforward, as the tutorial will explain below.

The first step is to provide your name that will be set Globally.

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

Next, select your e-mail; this can be fake if you prefer.

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

GIT Create Directory

First, create a directory for users who want to make a new directory strictly for GIT.

mkdir example-directory -p

Next, navigate to the directory.

cd example-directory -p

The next task is to use the initialization command, and this will create a hidden .git directory to store the configuration, history, and so on.

git init

You will see a terminal output stating the status of the directory being initialized, and you can additionally see the content using the following command.

ls -a .git

Print GIT CONFIG Details

To confirm GIT config users and details, use the config –list command

git config --list

Unless specified, Git stores details in the ~/.gitconfig file. You can review what is currently stored by using the cat command.

cat ~/.gitconfig

The sudo command with the git config command will set two separate user names and e-mails.

Store GIT Credentials

Using the following, you can enable the credential helper cache for users who want to store authorization details.

git config --global credential.helper cache

If you must use credential helper, it is advised to cache only for a limited time for increased security. For example, if you will be working today using GIT for 1 to 4 hours but won’t be touching it for maybe a few weeks, then set the expiry for 5 hours.

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

After 5 hours, the credentials will be deleted, securing your GIT.

Check Directory GIT Status

To view the status of a GIT repository, you can use the following git status command:

git status

While the above command helps with giving a status of the GIT, you can additionally list all git commands and sub.

Connect Remote GIT Repository

For users that need to work with GIT remotes to sync and download/upload changes, you will need to link the GIT. This can be done using the git remote command:

git remote add origin remote-repository-link

Commit GIT Changes

When you have completed changes in your GIT directory and want to SYNC it to push to the remote repository, use the following git commit command:

git commit -m "git message changelog"

Note: the -m “git message change” is the message that appears in the changelog.

Push GIT Changes

To push or send changes to the remote repository to SYNC in both versions, use the following git push command:

git push origin master

Pull GIT Changes

Alternatively, to pull or get changes from the remote repository to SYNC in both versions, use the following git pull command:

git pull origin master

Additional Commands & Tips

Update Git

For updates to GIT, they will be included with your standard system packages as you installed git-core with the DNF package manager. Use the following command to update and upgrade.

sudo dnf update --refresh

Remove Git

DNF Git Remove Method Command

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

sudo dnf remove git

This command will prompt the DNF package manager to locate and uninstall Git and its associated files from your Fedora system.

Compiled Git Version Remove Method

If you’ve installed Git from the source, the removal process requires manual intervention since no direct uninstaller is provided. Here’s how you can proceed:

Locate the Installation Directory:

If you followed the standard installation process, Git’s binaries are likely in /usr/local/bin. You can verify this with the terminal which command:

which git

Remove the Binaries:

Once you’ve identified the installation directory, you can manually remove the Git binaries:

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

Remove Associated Directories:

Additionally, you might want to remove other directories associated with Git:

sudo rm -rf /usr/local/libexec/git-core

After completing the above steps for either method, Git should be successfully removed from your Fedora system. To verify the removal, you can run:

git --version

If Git has been removed, this command should return an error indicating that Git is not found.

Conclusion

We’ve walked through the steps to install Git on Fedora Linux, either using the DNF package manager or by compiling the source code. Remember, mastering Git will amplify your coding efficiency, enhance collaboration, and streamline your development process. Don’t forget to explore Git’s advanced features as you grow more comfortable. So, dive in, start experimenting with your new Git setup, and see how it transforms your coding workflow!

Leave a Comment


Your Mastodon Instance
Share to...