Installing GIT on CentOS

Installing GIT on CentOS

This will be entirely a tutorial article aiming to walk you through installing GIT on CentOS and integrating it with GITHUB. Wow! Let’s get to it!

What’s GIT?

GIT is a version control tool that helps you to maintain and sync versions of things like files, directories, or code between developers and teams. People use it to make sure everyone is working on the same version of code, to track changes and maintain progress. GIT is reliable, widely used, open and free! So, let’s take you through the setup.

Installing GIT:

There are actually two ways you can set this up:

Method 1

The simplest way to install git is using CentOS’s own YUM package manager and you won’t need any prerequisites for this installation which is nice.

  1. Login with root credentials.
  2. Use YUM to install it using

  1.  The installation will handle itself automatically, just hit ‘y‘ when prompted.
  2. Once GIT is installed you can check the version using

This basically does it. But let’s keep going and make sure you’re up to date:

How to Updating GIT

  1. You need to know which distro and version you’re running. You can check this quickly with:

  1. While getting the base version of GIT is simple, you do need a couple of prerequisites. The first is getting RepoForge (formerly RPMForge repository, that you can grab from repoforge.org/use. Find and download the appropriate package for your distro.
  2. Once it’s downloaded, you will need to edit the repo and set it to enabled = 1 using

  1. Finally run the install command to update it

As far as this method goes, that’s all there is to it. But as you can see, to use this method you really need to have more information about your system beforehand. However, if you want to use GIT independent of the distro you’re running.

Method 2

In order to use this method, you’ll need a longer list of prerequisites installed.

  1. Use these commands to install the prerequisite software

  1. Afterward go to the GITHUB projects releasespage and download the latest one:

 

 

You can also rename the file if you like in the same command using:

  1. Once it’s downloaded, extract it and enter GIT’s root directory /git. Then configure it using the command:

 

 

  1. Now that it’s configured you can finall install it to your system with:

 

 

Aaaan you’re good! Now that it’s installed, you can verify which version you’re using:

 

 

Integrating With GITHUB

Finally all that’s left is integrating your local GIT with the GITHUB. To begin, you’ll need to put some information into your local configuration, used to identify your changes in commit messages.

 

 

Note: Hopefully it’s obvious that you should be using your own infromation in the above script

Now just use the following command to see if your information:

You can also use

 

Generating SSH Keys:

SSH keys are great because they let you connect to other servers without using your password every single time. Check out our article about other neat things you can do with SSH, since it’s a pretty versatile tool.

For our purposes, we’re going to generate a key and add it to our .ssh directory:

 

 

 

Now what’s left is adding the pub file (which is id_rsa) to the GITHUB profile.

Adding Pub File to GITHUB

Login to your GITHUB profile, go into your Personal settings page and get to the SSH and GPG keys panel. Name the key in the Title field.

Then open the pub file you created (id_rsa), copy its contents and paste them into the Key textbox in the SSH and GPG keys. 

Now that this is done, your local git can now maintain an SSH connection with remote GITS!

Cloning a Repository from GITHUB:

You’ll usually need to get a repository from GITHUB, just due to the nature of what “version control” implies; you need to get the latest version of the materials you’ll be working with.

If you’re connecting to GITHUB using SSH, like we helped you set up above, you’ll be using this command:

If you’re not going to be connecting SSH, you can use a universal command:

That about does it for this article! We went over finding the right file, download, and installation of GIT on your local machine. Then we went over connecting with SSH and cloning a remote repository. If you got any questions about this, or any other article, you can comment here to hit us up on Facebook and twitter.

Finally, we’ll leave you with a table of common commands you’ll be using with GIT.

-Until next time

by Rohit Kumar

GIT Commands
git clone Copy repos from remote servers
git add Add files to your local machine
git status Get a list of how many files are being committed
git pull Pull code from remote repo to a local one
git push Push code from your local repo to a remote one
git rm Remove files from local repo
git branch -a “remote url” Create a branch in master
git merge Merge branches
git reset Resets your index and working directory to the last time you made a commit
git log Log of all commits made
git rebase Merges a side branch into the master branch

 

Post Author: Rohit

Leave a Reply

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