
Git is an open-source distributed version control system that tracks changes in files and enables efficient tracking using in projects. Git enables multiple users to collaborate on a single file, maintain and track the history of all changes in a repository. Git works with repository hosting platforms like GitHub, GitLab, and BitBucket to support efficient collaboration and version control on different projects.
This article explains how to install Git on Rocky Linux 9. You will verify the pre-installed Git version on Rocky Linux 9 and install the latest stable version to use on your workstation.
Before you begin, you need to:
Git is pre-installed and available on Rocky Linux 9 by default. The default version may not be the latest, but it allows you to perform versioning tasks and manage repositories on your workstation. Follow the steps below to verify the default Git version before installing the latest or a specific version on Rocky Linux 9.
Check the pre-installed Git version on Rocky Linux 9.
Your output should be similar to the one below.
Run the Git help command to verify that you can access all Git options.
Output:
Dandified YUM (DNF) is the default package manager for Rocky Linux 9 that lets you install packages on your server. Git is available in the default DNF sources on Rocky Linux 9. The available version may not be the latest, but DNF provides a fast way to install a stable Git version. Follow the steps below to update the DNF package index and install Git.
Update the DNF package information index.
Install Git using the DNF package manager.
If you receive the following package output, the latest stable Git version in the Rocky Linux 9 repositories is already installed. Compile Git from source code to install the latest stable version.
Check the installed Git version.
Run the Git help command and verify access to all Git options.
Installing Git from source code allows you to install the latest version or a specific version required in your project. You can install the latest stable version, beta, or alpha releases that are not available in the default DNF package manager sources, providing you with more customization options. Follow the steps below to install the required packages and install a specific Git version from source code.
Update the DNF package information index.
Install all required packages for compiling Git on Rocky Linux 9.
Visit the Git archives page and download the latest stable Git version or specific version archive using wget. For example, https://mirrors.edge.kernel.org/pub/software/scm/git/git-2.49.0.tar.gz
Extract all files from the downloaded archive, depending on the version.
Navigate to the extracted Git directory depending on the downloaded version.
Run make to compile Git from source code and install it in the /usr/local directory.
Output:
Install Git from the compiled package to the /usr/local/ directory.
The above command replaces the default Git version in the /usr/local directory, allowing you to use the newly installed version.
Enter a new shell to apply the Git package information changes.
Test the installed Git version.
Your updated Git version should appear like the one below.
Run the Git help command and confirm access to all help options.
Git requires a correct username and email to tag on commit messages for staged files or changes. The git config command allows you to configure Git in your current repository or globally on your server. Follow the steps below to configure Git with your username and email information.
Configure the username to use with Git in all repositories.
Configure the email to use with Git in all repositories.
To specify the username and email information to use in an initialized repository, run the git config command without the --global option.
Display the Git configuration information.
Output:
Use the --local option to display the local Git information if configured in the current repository.
Open the .gitconfig file in your user's home directory to view the stored information.
Use the hidden .git/config directory in your current repository if you configured local Git information in your current repository.
Modify the Git configuration information if needed.
Save the file and exit the text editor after applying the new changes.
Git is installed and active on your Rocky Linux 9 server as performed in the instructions above. Follow the steps below to access and use Git in your project environment and authenticate with a remote repository provider such as GitHub to commit file changes.
Create a project like git-project.
Navigate to the project directory.
Create a basic configuration file like bash-script.sh.
Initialize the project directory using Git.
Output:
Use git add to stage all files in the directory.
Use git add with a file name to stage a specific file in the repository.
Create a new commit for the staged changes using Git.
Add a remote repository to sync with the local Git repository.
Log in to your Git repository provider, such as GitHub to enable push access.
Enter your GitHub username and password if prompted.
Push all local repository changes to the remote repository's main branch.
Pull the latest changes from the remote repository.
Track the Git commit history.
List all available remotes in your local repository.
List all branches in the current repository.
You have installed Git on Rocky Linux 9 and configured local repositories to synchronize changes in your project environment. Git enables versioning, allowing you to track and undo file changes on a server. Integrating Git with a remote repository provider like GitHub allows you to store local repository changes safely and roll back any files whenever needed. For more information, visit the Git documentation.
0 Comments
Be the first to comment and share your perspective with the community.