Install Git on CentOS 7.5

28/12/2020
Git
Git is a very popular Version Control System (VCS). It is written by the creator of Linux Kernel, Linus Torvalds. It is used to manage versions and snapshots of source codes of different software. It is used by software developers and software companies all around the world.

Git is a collaborative tool that helps many people work on the same project simultaneously. Git has a remote or central repository. This is where everyone pushes their changes. A developer clones a snapshot of the remote Git repository. It keeps a local copy of the remote repository in the developer’s computer. The developer makes changes to the source code and then he can push the changes back to a remote Git repository. The codes then can be checked and merged by the maintainer of that repository. This is how Git works.

In this article, I will show you how to install Git on CentOS 7.5 and the basics of Git. Let’s get started.

Installing Git

Git is available in the official package repository of CentOS 7.5.

First update the yum package repository cache with the following command:

$ sudo yum makecache

The yum package repository cache should be updated.

Now install Git with the following command:

$ sudo yum install git

Press y and then press <Enter> to continue.

Git should be installed.

You can check whether Git is working with the following command:

$ git –version

As you can see, Git is installed and working correctly.

Now let’s see how to use Git.

Initial Configuration of Git

Before you can use Git, you have to set some global Git variables, such as your name, email etc. You do not need to repeat these commands every time. This is a onetime configuration.

First set your full name with the following command:

$ git config –global user.name ‘YOUR FULL NAME’

$ git config –global user.email ‘YOUR EMAIL’

Enabling Colors in Git

By default, on CentOS 7.5, colors are disabled in Git. But colors make Git easier to use. Don’t worry, you can enable colors easily.

Run the following commands to enable colors in Git:

$ git config –global color.branch auto
$ git config –global color.diff auto
$ git config –global color.status auto
$ git config –global color.ui auto

Colors should be enabled in Git.

Initializing a Git Repository

To get a project or directory for Git ready, first you have to initialize it.

First navigate into your project directory with the following command:

$ cd YOUR/PROJECT/DIRECTORY

Now run the following command to initialize the directory for Git:

$ git init

The directory should be initialized as you can see from the screenshot below.

Tracking Files in a Git Repository

In a Git repository, you first tell Git what files or directories to track for changes. This is also called adding files or directories to the Git repository.

You can check the status of your Git repository with the following command:

$ git status

As you can see, I have one untracked file index.php

You can add index.php file to the Git repository as follows:

$ git add index.php

Now git status says index.php is ready to commit.

You can add all the files and directories in your newly created Git repository as follows:

$ git add -A

Committing Changes to the Repository

Whenever you make any changes to a file in your Git repository, you must add it to your Git repository with git add command as I showed you earlier. Then you have to commit the changes to the repository as follows:

$ git commit -m ‘A MESSAGE DESCRIBING WHAT YOU’VE CHANGED’

Checking All the Commits

You can check all the commits you’ve made with the following command:

$ git log
Or
$ git log –oneline

As you can see, my previous commit is listed.

Cloning a Git Repository

You can also clone an existing Git repository from GitHub or BitBucket. Just grab the Git repository URL and run the following command:

$ git clone YOUR_REPOSITORY_URL

The Git repository should be cloned.

A new directory should be created in the directory where you ran the command from as you can see:

If you navigate to the directory and check you should see all the commits of that Git repository:

That’s how you install and use Git on CentOS 7.5. Thanks for reading this article.

ONET IDC thành lập vào năm 2012, là công ty chuyên nghiệp tại Việt Nam trong lĩnh vực cung cấp dịch vụ Hosting, VPS, máy chủ vật lý, dịch vụ Firewall Anti DDoS, SSL… Với 10 năm xây dựng và phát triển, ứng dụng nhiều công nghệ hiện đại, ONET IDC đã giúp hàng ngàn khách hàng tin tưởng lựa chọn, mang lại sự ổn định tuyệt đối cho website của khách hàng để thúc đẩy việc kinh doanh đạt được hiệu quả và thành công.
Bài viết liên quan

Git LFS

Git has become the de facto version control system for software developers all around the world. This open-source, distributed...
28/12/2020

Install GitLab on Ubuntu 18.04

With the recent acquisition of GitHub by Microsoft, many corporations and organisations have decided to migrate away from...
28/12/2020

Configure Git Server with HTTP on Ubuntu

If you want to setup a Git HTTP Server for working with Git repositories privately, then this article is for you.  In...
29/12/2020
Bài Viết

Bài Viết Mới Cập Nhật

Reliable IPv4 and IPv6 Subnet Rental Services: The Perfect Solution for Global Businesses
23/12/2024

Tìm Hiểu Về Thuê Proxy US – Lợi Ích và Cách Sử Dụng Hiệu Quả
11/12/2024

Mua Proxy V6 Nuôi Facebook Spam Hiệu Quả Tại Onetcomvn
03/06/2024

Hướng dẫn cách sử dụng ProxyDroid để duyệt web ẩn danh
03/06/2024

Mua proxy Onet uy tín tại Onet.com.vn
03/06/2024