Learn Setting Up Git on Ubuntu 14.04

March 26, 2019

Table of Contents

    Git is a popular system for version management. It’s pretty simple to install. In this guide, we’ll see how we can install Git on Ubuntu 14.04.

    Step 1: Installing Git

    We can install Git without having to add any repositories.

    apt-get install git
    

    Step 2: Configuring Git

    Git works best if you give it some basic information: your name and your email address. You can set these options in Git with the following commands:

    git config --global user.name "John Appleseed"
    git config --global user.email "email@example.com"
    

    Committing

    The whole idea of Git is committing, so you can see the changes in each commit. For example, these could be a couple of commits:

    • Added class.php
    • Fixed example.php
    • Fixed variable in calendar.php

    You can view these in Git.

    Step 1: Creating a folder

    First, create a directory for your project:

    mkdir ~/git
    cd ~/git
    

    Now create a couple of files, like:

    touch example.html && touch index.html && touch contact.html
    

    You can now start the process of making this a Git project by executing the git init command while in the project directory:

    cd ~/git
    git init
    

    This will return the following response (assuming that ~/git refers to /home/test/git).

    Initialized empty Git repository in /home/test/git/.git/
    

    Step 2: Adding your files to Git

    Every time you create a new file and you want it to be included in Git, you need to tell Git that you want it to keep track of that file. For example, if we were to create a file called calendar.php and we would want to add it to Git, we would type:

    git add calendar.php
    

    Assuming that you are in the same directory as where the file you want to add (calendar.php) is.

    The problem with this is that you have to add each file manually. For example, if you already have a couple of files (in our case example.html, index.html and contact.html), you would need to add these 3 manually. With 3 files, that isn’t a huge task, but if you had more files, then it would take a considerable amount of time. Luckily, we can use . which adds all files not currently in Git:

    git add .
    

    Step 3: Committing one or more files

    Congratulations, you’re ready to commit! Committing is the process of telling Git you’ve made a number of changes and it should put them in the “changelog”. After all, that’s the whole point. In order to properly use commits, we must add a commit message. This allows you to keep track of all the changes. This can be anything you want; it’s good practice to use something that you will understand though.

    git commit -m "Initial commit" -a
    

    Congratulations! You can now use Git on your VPS.

    Need help?

    Do you need help setting up this on your own service?
    Please contact us and we’ll provide you the best possible quote!