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 40 or 39.
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
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
Compiling from the source code is the way for those who require a specific version of Git that is not available through the DNF package manager or wish to install Git with custom configurations.
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
Basic Git Commands
The following parts will cover some typical setups and commands used daily by GIT users. This is not the complete list; GIT has many commands and configurations, but newer users may find some examples helpful. For users seeking more advanced requirement options or usage, I would check out the Git documentation for more information in the long term.
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, which 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
You can enable the credential helper cache for users who want to store authorization details using the following.
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 give the GIT status, you can additionally list all git commands and subcommands.
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 has not been found.
Conclusion
We’ve walked through the steps to install Git on Fedora Linux using the DNF package manager or compiling the source code. Mastering Git will amplify your coding efficiency, enhance collaboration, and streamline your development process. As you grow more comfortable, remember to explore Git’s advanced features. So, dive in, experiment with your new Git setup, and see how it transforms your coding 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.