How do I install Git on Rocky Linux 8?

Install Git Rocky Linux

In the following tutorial, you'll learn how to install Git on Rocky Linux 8, using command lines. Following installation, we'll look at some basic commands for using Git.

When it comes to writing scripts (for devops, for example) or being a developer, Git is a must! It's a free, open-source version control system which, thanks to its flexibility, is capable of managing both small and large projects. As well as keeping track of versions, there's a collaborative aspect, as several developers can work together on the same project, benefiting from code updates (and branch management working on several versions). Are you ready to install Git? I hope so!

As with every installation, you need root access or a user with sudo access to follow this tutorial. Before getting to the heart of the matter, update your system to ensure that all current packages are up to date.

sudo dnf upgrade --refresh

1. Install Git

On Rocky Linux (base Linux), installing Git is easy, since you can get the latest version with the following command:

sudo dnf install git -y

We can say it now: we have justinstalling Git on Rocky Linux ! I think it's important to learn a few commands to get started with Git: that's what we're going to do now. Installing Git will differ from one system to another, especially between Linux, Windows and macOS, but Git commands are the same on all systems.

2. Getting started with Git

The following sections cover some typical commands that all Git users need to know, whether on Rocky Linux or another system! 😉

A. Add a Git user

Following installation, you'll need to configure standard parameters such as the name and e-mail address that will be associated with git commit messages. To define a global name, use the "git config" command with the appropriate options. Generally speaking, you interact with Git via the "git" command.

git config --global user.name "TUTOBOX"

That's for the name. For the e-mail address, we're targeting a different property (you can use a bogus e-mail).

git config --global user.email "git@tutobox.fr"

Note git config: using the sudo command with the "git config" command is not without consequences, as you can define two separate usernames and e-mails.

B. Creating a Git folder

Git needs storage space in which to work: this is where you're going to store your project files. We need to create this folder, which we'll use exclusively for Git.

mkdir /home/tutobox/git-projet1 -p

Then, we position ourselves in this file:

cd /home/tutobox/git-projet1 -p

From a file system point of view, this directory exists. However, it is not initialized at the Git level. The following command is used for initializationwhich will make it possible to create a hidden directory named ".git to store the configuration, history, etc. of this project.

git init
Install Git Rocky Linux

You'll see an output in the Linux terminal indicating the status of the directory being initialized. For the more curious, feel free to look at the contents of the folder using the following command :

ls -a .git

Your project files (scripts, images, etc.) should be added to this folder so that they can be tracked by Git. However, moving the contents of your project into this folder isn't enough: you need to add them to your project via a Git command.

For example, you can create a script called " script.sh " in " /home/tutobox/git-projet1/ "

touch script.sh

Then add it to Git like this:

git add script.sh

To add all files at once :

git add .

C. Display Git configuration

To view the Git configuration and make any necessary changes, use the following command:

git config --list

Where is this information stored? Well, you should know that Git stores configuration details in the ~/.gitconfig file. Here again, you can display the contents of this file directly with the cat command:

cat ~/.gitconfig

D. Caching Git IDs

For users who wish to cache Git credentials and associated permissions, you can enable caching by running the following command:

git config --global credential.helper cache

In addition, it is strongly recommended to limit the caching time for security reasons. For example, if you plan to work for 7 hours (or 25,200 seconds) with Git, you can set the expiration time accordingly (value expressed in seconds). This is set with the "-timeout" parameter.

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

After 7 hours, the credentials will be removed from the cache, locking the Git in place so to speak.

E. Viewing the status of a Git repository

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

git status
Git status

For information on the latest commits, you can consult the logs :

git log

F. Commit changes

When you've finished making changes to the files in your Git project, you need to commit the changes so that they're recorded in Git (so to speak). Whether the Git repository is local on your PC or remote, committing is inevitable. If it's a remote directory, you'll then have to push the changes to the remote repository. This is called a commit, and a reason is associated with it to facilitate tracking.

git commit -m "First version of the script
git commit -m "Fixed a bug in script.sh" file
Git commit

For a remote repository, it will first be necessary to connect the remote repository (Git Server, GitLab, GitHub, etc.). For example, connection to a GitLab repository is via an SSH and HTTPS connection, as explained in the official documentation :

git remote add origin mon-depot-git-distant.tutobox.fr

G. Push for change

To push changes to the remote repository in the associated branch :

git push origin master

Conversely, to download changes from the remote repository to the local version, use the command below. To create a local copy of a remote repository, use the " git clone "It also requires Git to be installed upstream.

git pull origin master

I remind you again that "git" commands require Git to be installed, regardless of the action to be performed.

H. Create a new branch

To create a new branch for the development of new features or to work on debugging a problem, you can create a new branch in addition to the "master" branch. Here's how to create a new branch named "debug" and switch directly to it (the git switch command is used to switch from one branch to another):

git switch -c debug

Next, you can list your branches:

git branch

I. Update the Git package

Git updates are carried out using Rocky Linux's DNF package manager, so it's very simple. Use the following command to update Git :

sudo dnf update --refresh

Thanks to this new article in the tutorial box, you now know how to install Git on Rocky Linux, and you're familiar with some very practical basic commands! Now it's up to you to delve into the subject: it may not be easy at first, but it's an excellent tool!

Resources :

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *