Howto install git on debian 8

October 21, 2015

Git is GPL version control system used primarily for distributed development of projects, even ones with large amounts of data. The important part here is Version Control System — it means that it’s a software that track changes in files and compare different versions, and do many other nice things, like going back to previous versions of a certain file. Every working directory in Git is a full-fledged repository which has a complete history. Therefore in git one can work without a network connection and sync his/her changes when the network is there.

Requirements

Following items are required for this tutorial:

  • A server or VPS running Debian 8
  • A root or sudo user account

Installing Git

Before you install Git, make sure that your system is updated by executing the following command:

Now install Git with following apt-get command:

This is the only command that is needed to install Git. The next step is to configure Git.

Configuring Git

Git implements version control using mainly two settings:

  • A username
  • The user’s email

This information will be used in every commit one make with Git so it can track who is making which commits. All these setting are stored in .gitconfig in your home folder.

So we need to add these two settings in our Git configuration file. This can be done with the help of the git config utility or we can edit directly .gitconfig file. Let’s first do it by git config utility. Here’s how:

Set your Git username:

Set your Git email:

View all Git settings:

You can view these newly-configured settings (and all the previously existing ones, if any) using the –list parameter in the git config utility.

You will see your user settings:

If we want to get our hands dirty with the Git configuration file, simply fire up nano and edit .gitconfig content:

 

This is the basic configuration one need to get up and running with Git. Adding your username and email is not mandatory, but it is recommended. 
Congratulations on your very own Git installation.

Here is a simple guide for getting started with git, no deep shit. 

Create a new repository

Create a new directory, open it and perform a

to create a new git repository. The git inits command creates a new Git repository. It can be used to convert an existing, unversioned project to a Git repository or initialize a new empty repository. Most of the other Git commands are not available outside of an initialized repository, so this is usually the first command you’ll run in a new project. Executing git init creates a .git subdirectory in the project root, which contains all of the necessary metadata for the repo. Aside from the .git directory, an existing project remains unaltered.

Check out a repository

To create a working copy of a local repository by running the command

when using a remote server, the command will be

Workflow

Our local repository consists of three “trees” maintained by git. the first one is our Working Directory which holds the actual files. the second one is the Index which acts as a staging area and finally the HEAD which points to the last commit we’ve made.

Add and Commit

We can propose changes (add it to the Index) using

This is the first step in the basic git workflow. To actually commit these changes we use git commit -m “Commit message” Now the file is committed to the HEAD, but not in the remote repository yet.

Pushing changes

Our changes are now in the HEAD of our local working copy. To send those changes to remote repository, execute

Change master to whatever branch you want to push your changes to. If we have not cloned an existing repository and want to connect our repository to a remote server, we need to add it with

Now we are able to push your changes to the selected remote server

Happy branching!

Meierwiesenstrasse 52
CH-8064, Zurich Switzerland

387 Jaswant Nagar, Garha Road
Jalandhar 144007 Punjab India

Copyright 2013 DilTech Solutions
Design & Develop By Diltech Solutions