Getting started with Git on Linux

Git is an open-source distributed version control system used by the software developers for small and large projects. It comes with very useful features and it is very easy to learn. In this tutorial we are going to show you how to install Git on a Linux VPS and explain the basics of Git so you can start using it.

1. What is Git

Git is a distributed version control system which is used to track the code changes in software development. Apart from tracking the code changes, Git allows you to revert to a previous stage. The features like cheap local branching, multiple workflows and convenient staging areas make Git one of the most popular version control systems among software developers.

2. Install Git on Linux

If you are using an Ubuntu VPS, go ahead and install Git on your system using the commands below:

sudo apt-get update
sudo apt-get install git

If you are using a CentOS VPS, you can use the following command to install Git:

sudo yum install git

To check which version of Git is installed on your system, use:

git --version

3. Set up Git on Linux

Now that you have Git installed on your Linux VPS, you might like to proceed with the Git configuration. Basically, you will need to configure your name and email address. That way the commit messages will contain the correct information. To update your name and email, you can use the following commands:

Once you create a file, you need to add the file contents to the index. You can do that by using the following command:

git add

However, this command doesn’t affect the repository. To record the changes to the repository, you should run the command below:

git commit

For more Git command line options you can use the following command:

git --help

This is the list of most commonly used Git commands:

- add Add file contents to the index
- bisect Find by binary search the change that introduced a bug
- branch List, create, or delete branches
- checkout Checkout a branch or paths to the working tree
- clone Clone a repository into a new directory
- commit Record changes to the repository
- diff Show changes between commits, commit and working tree, etc
- fetch Download objects and refs from another repository
- grep Print lines matching a pattern
- init Create an empty Git repository or reinitialize an existing one
- log Show commit logs
- merge Join two or more development histories together
- mv Move or rename a file, a directory, or a symlink
- pull Fetch from and merge with another repository or a local branch
- push Update remote refs along with associated objects
- rebase Forward-port local commits to the updated upstream head
- reset Reset current HEAD to the specified state
- rm Remove files from the working tree and from the index
- show Show various types of objects
- status Show the working tree status
- tag Create, list, delete or verify a tag object signed with GPG

For more information and usage examples you can read the official Git documentation which is available at https://git-scm.com/doc.

Of course you don’t have to do any of this if you use one of our Git Hosting services, in which case you can simply ask our expert Linux admins to install Git for you. They are available 24×7 and will take care of your request immediately.

PS. If you liked this post please share it with your friends on the social networks using the share buttons or simply leave a reply below. Thanks.