Git is an open-source and popular tool to proveide a distributed version control platform generally used by developers and companies, to work individually or in a community using various platforms and IDEs. Here we learn the command to install Git on Rocky Linux 8 or AlmaLinux 8.
Git, first released in 2005, was designed for teams to use branches and merges on a regular basis to build up a clear history of the project. Even every team member can have a clear view to visualize the branches and merges of a project, using Git’s inbuilt tools. It is platform-independent and can therefore be used in almost any environment.
When multiple developers work on the same project from different locations, version control makes it easy to add changes independently while leaving tracks and logs. This not only offers transparency- who did what and when, but also gives access to older versions of the project at a later point in time.
The key feature that makes Git different from other version control systems is it doesn’t depend on a centrally stored database, instead, it relies on a distributed system. Therefore, there is no central storage, this implies each member of a project team has a kind of their own copy of the project database – the repository.
Out of the box, Git comes as a command-line tool, however, there are many thirds party GUIL clients available to manage it graphically. The popular GitHub and GitLab web interface for Git projects are some of those. Apart from web-based GUI clients, Desktop ones are also available.
- Steps to install Git on AlmaLinux or Rocky Linux 8
Steps to install Git on AlmaLinux or Rocky Linux 8
Commands given here to set up Git on RPM-based Rocky or AlmaLinux will be the same for other similar Linux such as CentOS, Fedora, Oracle Linux, RedHat, and others.
- Rocky or AlmaLinux
- A non-root sudo user
- Internet connection
2. Run DNF update
To ensure our system repository cache and all the already installed system packages are up to date; once run the system update command given below:
sudo dnf update
3. Command to Install Git on AlmaLinux or Rocky Linux 8
We don’t have to add any extra repository, the popular Git tool is already available through the base repo of both Almalinux and Rocky. Hence, simply execute the installation command using the DNF package manager.
sudo dnf install git -y
4. Check Version
Once the installation is completed, let’s confirm the same by checking the Git-installed version.
5. Configure Git
Now that we have git installed on our machine, we still need to add some configurations. There are a lot of options available to you (like the appearance and functionality of the client), but we’ll only do the two most important configurations here. On the one hand, we set our username, and on the other hand our email.
Any action we do in Git will now have a stamp of the name and email address we just provided. This way other users always know who did what and when. This brings order to the chaos, especially in large projects with many developers working on them.
6. Create a new repository – git init
As we mentioned earlier, git stores its files and history directly as folders in your project. To set up a new repository, we need to open our project directory and run git init. This will enable Git for that specific folder and create a hidden .git directory to store the repository’s history and configuration. If you don’t have any project already and want to start from scratch then first create the one with the name you want to give to your project.
Create a directory
Get into the created directory
Now, initialize git local repository
You can see the content
ls -a .git
7. Checking the status of the repository – git status
To have the git status, the command is:
To list all git commands and sub-commands
git help -a
Get help for some particular command
git help <command>
8. Connect remote git repository
If you want to upload something to a remote repo, we first need to connect to it. For example, to link the one you have on GitHub, BitBucket, or another service, we run the following line in the terminal:
git remote add origin remote-repository-link
For example, you have your own repository on GitHub and want to pull or push the changes into that. Then first switch to your Project directory where you have initialized the Git. After that connect the remote directory using the above-given command.
git remote add origin https://github.com/h2smedia/HowTo.git
To pull the repository files:
git pull origin master
To push the changes made to files:
git push origin master
Note: Pushing requires a password, however, if you are using GitHub- password-based authentication is no longer usable in it. The user has to go for a token-based instead. Know more about it at the official blog of GitHub.
9. Remove or Uninstall
If you don’t need Git on Almalinux or Rocky Linux 8, then we can remove it using the same command we have used to install the same but with a different option.
sudo dnf remove git -y
For more information refer to the Git documentation.
10. Video Tutorial