How to Install Git on Linux
Installing Git on Linux brings you speed and performance. It is built to work on the Linux kernel, so it will handle large repositories. If you wish to reduce the overhead of runtime associated with higher-level languages than C, this is what you need. In this article, you will learn how to install Git on Linux. This guide is also helpful for users who have no idea what is Git. The definition of Git, the required steps to installing it on Linux, and finally creating a new project and committing changes to the Git repository will be explained completely.
Firstly, as you need a Linux VPS to experience Git on it, find the cheapest plans with 24/7 support and purchase with one click.
Introduction to Git?
Git is a free and open-source distributed version control system. Both small and very large projects are handled by Git with speed and efficiency. Git is really fast to perform all operations locally. Centralized systems that have to communicate with a server somewhere constantly, will appreciate the huge speed of Git. Enabling multiple developers to work together on non-linear development, Git tracks changes in source code.
To find the best way to manage various code versions, let’s go through this article and see how to merge them with the main code after testing.
What is VCS and how it works?
VCS is the abbreviation of the version control system. As a developer, you can use the version control system (VCS) to track file changes. Various versions of files and changes made to each version are created by VCS. In this way, you will be able to switch between various versions of the files seamlessly. By storing a collection of file changes on the repository, it helps track changes in source code files. A version control system can track changes in binary data, not just text files.
There are various types of version control systems such as:
- Localized Version control systems
- Centralized version control system
- Distributed Version control system
Git Features
Using Git enables you to not submit your codes to the central server without having copies of your own. Once you install Git, all changes made to the source code will be known, and you can communicate with other developers. Here is more:
- Free and open source
- Frictionless Context Switching
- Supports non-linear development
- Distributed development
- Tracks history
- Role-Based Code lines
- Branching is easier
- Creates backups
- Feature Based Workflow
- Supports collaboration
- Scalable
- Disposable Experimentation
- Distributed development
Head over to the Git Community to find any reported issues quoted from users and see what also are downsides of Git are.
Prerequisites to install Git on Linux
Before tracing the installation steps on this guide, make sure you are logged in as root or a user with sudo privileges.
Git Installation on Linux
Git should have been installed on your operating system with all the major Linux distributions. But depending on the system you are using, it may not be installed. Git packages are available via apt. So, run the command below on your system.
Debian/Ubuntu
sudo apt-get update && sudo apt-get upgrade -y sudo apt-get install git -y
Arch Linux
sudo pacman -S Git
Fedora/Red Hat/CentOS
sudo yum install git
sudo dnf install git
To verify that if the installation was successful, type:
$ git --version
git version 2.9.2
How to build Git from source on Linux?
Debian / Ubuntu
To build on Linux, Git requires several dependencies. To make them available. Run:
$ sudo apt-get update
$ sudo apt-get install libcurl4-gnutls-dev libexpat1-dev gettext libz-dev libssl-dev asciidoc xmlto docbook2x
Now, use the command below to clone the Git source.
$ git clone https://git.kernel.org/pub/scm/git/git.git
Then, type the following command to build Git and install it under /usr
, run make
:
$ make all doc info prefix=/usr
$ sudo make install install-doc install-html install-info install-man prefix=/usr
How to Configuration Git on Linux?
After a successful installation, you are ready to access and use all Git’s commands working with local and remote repositories. First-time use needs a configuration. Running the below command allows you to configure your Git username and email address, and the default text editor.
Note: Replace OperaVPS with your own.
$ git config --global user.name "OperaVPS"
$ git config --global user.email "[email protected]"
git config --global core.editor vim
Then, use the following command to view the git configuration.
git config --list
user.name=myusername
[email protected]
core.editor=vim
How to Set up/Use Git repositories on Linux?
Files and directories are collected in the repository with their respective changes tracked by the version control system. Commits manage or tracking changes in a repository. Using commits allows you to apply the changes or revert to a specific change within the repository.
In the case of having a project directory, you can initialize it using the command below to use as a git repo and track changes. Then, Git will initialize the directory as a repository and creates a .git directory used to store all the configuration files.
git init
Now, type the following command to start tracking changes. For example, to add the file, reboot.c:
git add reboot.c
Now you can add the files in that directory and start tracking changes if you run the command below:
git add .
To add the message (file) indicating the changes to the files, just use something like the following command:
git commit -m “Initial Commit.”
Clone a remote repository
It is possible to work with remote repositories. Cloning is to copy all the files in a remote repo to the local repo. So, type:
git clone https://github.com/linuxhint/code.git
Run the command below to view the status of the files in the repository.
git status
Obviously, after running the command above, you will see whether the files in the repository are changed or not.
Also, you can get all the changes from the remote repository and merge them into the local one. When you have a clone repository, run the following command to update the local repo from the remote.
git fetch
Create and Delete a remote repository
Use the following command to create a new remote repository.
git remote add new_repo https://github.com/operavps/new_repo.git
Also, whenever you wish to delete a remote repository from the command line, type:
git remote rm https://github.com/operavps/new_repo.git
That’s It! Just start working with local and remote repositories.
do i need to install git to use github?
No, you do not have to. But you need to consider that if you need to use Visual Studio, GitHub is required too. Also, you have to install and configure Git on your computer to use the Git command. Therefore, you can install GitHub CLI to use GitHub from the command line.
how to check git version?
To check your current and latest version of Git, run:
git --version
The output is something like:
git version 2.7.4
Conclusion
In this article, you learned how to install Git on Linux. Now you are familiar with Git and the way it works as a version control system. While reviewing Git features you may get interested to install and use it. If yes, consider that you will have an entire copy of the code on your local systems and observe all changes made to the source code. And you should say hello to regular communication between other developers. Share your new experience with other developers and ask your questions right below here.