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, along with an automated update script to keep your source-compiled installation current.
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 and ensures you receive the latest security patches:
sudo dnf upgrade --refresh
Choose Your Git Installation Method
Fedora offers two ways to install Git: the DNF package manager or manual source compilation. The following table outlines the key differences to help you choose the right approach for your needs:
| Method | Channel | Version | Updates | Best For |
|---|---|---|---|---|
| DNF Package Manager | Fedora Repos | Latest stable | Automatic via dnf upgrade | Most users who want simplicity and automatic security updates |
| Source Compilation | Git Tags | Any version | Manual recompilation | Developers needing specific versions or custom compile-time options |
For most users, the DNF method is recommended because it provides automatic security updates and requires minimal maintenance. Fedora typically ships Git updates within days of upstream releases, so you rarely need to compile from source unless you have specific requirements.
Install Git with DNF (Recommended)
Fedora maintains Git in its official repositories, so installation through DNF requires a single 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
Compiling from source is useful when you need a specific Git version unavailable through DNF, want to enable custom compile-time options, or need to test development builds. This section walks through the complete build process, including automatic version detection to ensure you always compile the latest release.
Install Build Dependencies
Before downloading the source code, install the required build tools and development libraries. First, install the Development Tools group, which provides GCC, make, and other essential compilation utilities:
sudo dnf groupinstall "Development Tools"
Next, install the development headers that Git requires for HTTPS support, compression, and localization:
sudo dnf install libcurl-devel expat-devel openssl-devel zlib-devel gettext-devel perl-ExtUtils-MakeMaker
These packages provide essential build-time features: libcurl-devel enables HTTPS/HTTP operations, expat-devel provides XML parsing for remote helpers, openssl-devel adds TLS support, zlib-devel handles compression, gettext-devel supports internationalization, and perl-ExtUtils-MakeMaker builds Perl-based utilities.
If you regularly compile software from source, familiarize yourself with build tools like CMake on Fedora for managing complex build configurations.
Download and Extract Source Code
With dependencies in place, download the latest Git source code. The following command uses the GitHub API to automatically detect the newest stable version and download the corresponding archive:
curl -s https://api.github.com/repos/git/git/tags | grep -oP '"name": "v\K[0-9]+\.[0-9]+\.[0-9]+' | head -1 | xargs -I{} wget https://github.com/git/git/archive/refs/tags/v{}.tar.gz
This command chains several operations together: curl fetches the tag list from GitHub’s API, grep extracts the latest version number, and xargs passes it to wget for downloading.
If you prefer to download a specific version manually, visit the Git tags page and replace the automatic command with:
wget https://github.com/git/git/archive/refs/tags/vX.Y.Z.tar.gzwhere X.Y.Z is your desired version.
Next, extract the downloaded archive using wildcards to handle any version number:
tar -xzf v*.tar.gz
Then navigate into the extracted source directory:
cd git-*/
Compile and Install Git
With all prerequisites in place, compile Git by executing the make command. The prefix=/usr/local option installs Git to /usr/local/bin, keeping it separate from system-packaged software:
make prefix=/usr/local all
Compilation typically takes a few minutes depending on your hardware. You should see output similar to:
CC credential-store.o
CC diff-no-index.o
CC help.o
CC daemon.o
...
LINK git
BUILTIN git-add
BUILTIN git-am
BUILTIN git-annotate
After compilation finishes, install Git to your system. This step requires elevated privileges because it writes to /usr/local:
sudo make prefix=/usr/local install
Finally, verify the installation by checking the Git version:
git --version
You should see output confirming the version you compiled:
git version 2.52.0
Since /usr/local/bin typically takes precedence in your PATH, the source-compiled version will be used instead of any DNF-installed version. You can confirm the installation location with:
which git
/usr/local/bin/git
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 provided by GitHub or GitLab, or a pseudonymous email:
git config --global user.email "YOUR EMAIL"
Create Your First Repository
To start tracking a project, first create a directory for your project:
mkdir -p ~/my-project
Then navigate into the directory:
cd ~/my-project
Now initialize it as a Git repository:
git init
You should see confirmation output:
Initialized empty Git repository in /home/user/my-project/.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
By default, credentials remain cached for 15 minutes. For longer sessions, set a custom timeout in seconds. This example caches credentials for 5 hours (18000 seconds):
git config --global credential.helper "cache --timeout=18000"
After the timeout expires, your credentials are 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. Replace the URL with your actual repository address:
git remote add origin git@github.com:username/repository.git
For secure authentication, consider configuring SSH on Fedora and using SSH URLs as shown above. SSH key authentication eliminates password prompts while providing stronger security than HTTPS with password caching.
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 and new 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
mainas the default branch name instead ofmaster. If working with older repositories, replacemainwithmasterin push and pull commands.
Pull Changes from Remote
To fetch changes from the remote repository and merge them into your local branch, use:
git pull origin main
Troubleshoot Common Git Issues
This section addresses common problems you may encounter when using Git on Fedora and provides tested solutions.
SSL Certificate Errors
If you encounter SSL certificate verification errors when cloning or pushing to repositories, such as SSL certificate problem: unable to get local issuer certificate, the issue typically relates to missing or outdated CA certificates.
First, update your system’s CA certificate bundle:
sudo dnf upgrade ca-certificates
If the problem persists with a corporate proxy or self-signed certificates, you can configure Git to use a specific CA bundle:
git config --global http.sslCAInfo /path/to/your/certificate.crt
Avoid disabling SSL verification entirely with
http.sslVerify=falseas this exposes you to man-in-the-middle attacks. Only do so temporarily for testing and never in production environments.
Git Behind a Proxy
If your network requires a proxy, configure Git to route traffic through it:
git config --global http.proxy http://proxy.example.com:8080
git config --global https.proxy http://proxy.example.com:8080
For proxies requiring authentication:
git config --global http.proxy http://username:password@proxy.example.com:8080
To remove proxy settings later:
git config --global --unset http.proxy
git config --global --unset https.proxy
Permission Denied When Pushing
If you receive Permission denied (publickey) when pushing to a remote repository, your SSH key may not be configured correctly. Verify that your SSH key is loaded:
ssh-add -l
If no keys are listed, add your key to the SSH agent:
ssh-add ~/.ssh/id_ed25519
Ensure your public key is also added to your GitHub, GitLab, or other Git hosting service account settings. For detailed SSH setup instructions, see our guide on SSH on Fedora.
Manage Git Installation
Update DNF-Installed 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
Update Source-Compiled Git
For source-compiled installations, you can either repeat the manual compilation process or use the following update script. This script automatically detects the latest Git version, downloads the source, compiles it, and installs the update.
First, create the update script:
sudo tee /usr/local/bin/update-git <<'EOF'
#!/bin/bash
set -e
# Check for required tools
for cmd in curl wget make gcc; do
if ! command -v $cmd &>/dev/null; then
echo "Error: $cmd is required but not installed."
exit 1
fi
done
# Get current installed version
CURRENT_VERSION=$(git --version 2>/dev/null | grep -oP '\d+\.\d+\.\d+' || echo "none")
# Fetch latest version from GitHub API
LATEST_VERSION=$(curl -s https://api.github.com/repos/git/git/tags | grep -oP '"name": "v\K[0-9]+\.[0-9]+\.[0-9]+' | head -1)
if [ -z "$LATEST_VERSION" ]; then
echo "Error: Could not fetch latest version from GitHub API."
echo "Check your internet connection or try again later."
exit 1
fi
echo "Current version: $CURRENT_VERSION"
echo "Latest available: $LATEST_VERSION"
if [ "$CURRENT_VERSION" = "$LATEST_VERSION" ]; then
echo "Already up to date."
exit 0
fi
echo "Updating from $CURRENT_VERSION to $LATEST_VERSION..."
# Create temporary build directory
BUILD_DIR=$(mktemp -d)
cd "$BUILD_DIR"
# Download and extract
echo "Downloading Git $LATEST_VERSION..."
wget -q "https://github.com/git/git/archive/refs/tags/v${LATEST_VERSION}.tar.gz"
tar -xzf "v${LATEST_VERSION}.tar.gz"
cd "git-${LATEST_VERSION}"
# Compile and install
echo "Compiling..."
make prefix=/usr/local all -j$(nproc)
echo "Installing..."
sudo make prefix=/usr/local install
# Cleanup
rm -rf "$BUILD_DIR"
# Verify
NEW_VERSION=$(git --version | grep -oP '\d+\.\d+\.\d+')
echo "Successfully updated to Git $NEW_VERSION"
EOF
sudo chmod +x /usr/local/bin/update-git
Since the script installs to /usr/local/bin, you can run it from any directory:
update-git
Example output when already up to date:
Current version: 2.52.0 Latest available: 2.52.0 Already up to date.
When an update is available, the script automatically downloads the new version, compiles it, and installs the updated binaries.
Avoid automating this script with cron. Compilation can fail due to missing dependencies, network issues, or API changes. Always run the script manually so you can monitor the output and address any problems before they affect your system.
Remove Git
Remove DNF-Installed Git
If you installed Git using the DNF package manager, uninstalling it is straightforward:
sudo dnf remove git
DNF locates and uninstalls Git along with its associated files from your Fedora system.
Remove Source-Compiled Git
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 reside in /usr/local/bin. Verify the location:
which git
For source-compiled installations, you should see:
/usr/local/bin/git
Step 2: Remove Git Files
After confirming the location, remove the Git binaries and associated directories:
sudo rm -f /usr/local/bin/git /usr/local/bin/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*
If you created the update script, remove it as well:
sudo rm -f /usr/local/bin/update-git
Verify that Git has been fully removed:
git --version
If Git is removed, this command returns 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 -f ~/.gitconfig ~/.git-credentials
Removing
~/.gitconfigdeletes your global Git settings (name, email, aliases, and preferences). Removing~/.git-credentialsdeletes 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 Links
For further reading and official documentation, refer to these resources:
- Git Official Website: Official project information, download options, and feature overview.
- Git Tags on GitHub: Source code releases for downloading and compiling specific versions.
- Git Reference Documentation: Complete command reference and usage guides.
- Git Community: Mailing lists, IRC channels, and contribution guidelines.