Git for begginers 
Tags: git, github, gitlab, tutorial
Published: 2020-02-08 16:27:38

---
title: Git for begginers 
published: true
description: 
cover_image: https://i.imgur.com/pzAeg41.png
tags: git , github , gitlab , tutorial

---
## Table Of Contents
 [Introduction](#Introduction)
 [Version Controle System](#VersionControlSystem)
  * [benifit](#benifit)
  * [Centralized VCS](#centralizedVCS)
  * [Distributed VCS](#distributedvcs)
  * [comparison between Git and SVN](#comparison)
  * [Git](#Git)
  * [Commit](#Commit)
  * [Branch] (#Branch)
  * [let's get started](#let's get started )
  * [Conclusion](#Conclusion)


<a name="Introduction"></a>
<h1>Introduction</h1>
![](https://i.imgur.com/xCAtgy6.png)
in this post you will learn a Version Control System called git . you will be able also to distingue the difference between centralized vcs and distributed vcs . and mostly be able to use git in your individual  project  , group project or community project . 
<a name = "VersionControlSystem"></a>
<h1>Version Controle System</h1>
Version control systems are a category of software tools that help  you change  to source code over time. this  software keeps track of every modification to the code in a special kind of database. If a mistake is made, developers can ___turn back the clock___ and compare earlier versions of the code to help fix the mistake while minimizing disruption to all team members. so the main benifit of using these softwares are : 
<a name ="benifit"></a>
![](https://i.imgur.com/IExXqQz.png)
    <h3>benifit</h3>
        *turn back the clock whatever you want 
        *keeps track of everything 
        *facility in recreating things and evolute 
<a name="centralizedVCS"></a>
    <h3>Centralized VCS</h3>
    ![](https://i.imgur.com/AsNO1re.jpg)
A centralized version control system works on a client-server model. There is a single, (centralized)master copy of the code base, and pieces of the code that are being worked on are typically locked, (or “checked out”) so that only one developer is allowed to work on that part of the code at any one time. Access to the code base and the locking is controlled by the server. When the developer checks their code back in, the lock is released so it’s available for others to check out. Exemple  : 
{% tag svn %}
<a name ="distributedvcs"></a>
    <h3>distributed vcs</h3>
    ![](https://i.imgur.com/7Nvwnec.jpg)
The whole approach of central VCS is reversed and each collaborator will have the complete repository on his local machine i.e. the complete revision history, all the branches, tags, commit information is present on the local machine. We do not have a notion of a central server, but we can configure any repository to be a central repository to treat as a source of truth . Exemple 
{%tag git%} 
<a name ="comparison"></a>
    <h3>comparison between Git and SVN</h3>
    ![](https://i.imgur.com/N0EhfDF.png)

|                                           | SVN                                         | GIT |
| -------------                             |:-------------:                              | -----:      |
| Version management                        | Central                                     | Distributed |
| Repository                                | A central repository in which working copies are generated | Locally available repository copies in which files and documents can be worked on |
| Change history                         | Only complete in the repository. Working copies only contain the newest version  | Repository and working copies contain the complete history |
|Network connection     | Needed for access | Only necessary for synchronization |

<a name="Git"></a>
![](https://i.imgur.com/1rZSN0F.jpg)
<h1>Git</h1>
Now for the main Topic Git !!! as i mentiond eraly git is a timemachine for our code. we can go back to any moment of life of our programme at anytime . and that's thanks to [Commit](#Commit) . 
<a name="Commit"></a>
<h2>Commit</h2>
![](https://i.imgur.com/4df9ICD.png)
it represent a life-moment in code , that's why i advice all of you to commit every important add ( for examaple : function , methode , class , test ... ) . 
it has a unique id , date , author name and email included and none of this information can be changed . 
<a name="Branch"></a>
<h2>Branch</h2>
branches can be represented by team member (every team member have it owns branch ) or by code version (we can have in the same project , 2 branches and every branch represent different logic and code ) 
<a name="let's get started "></a>
<h1>let's get started </h1>
1.Config 
now let's jump to our terminal (OS X , Linux  . Windows users need to download [git bash](https://github.com/git-for-windows/git/releases/download/v2.25.0.windows.1/Git-2.25.0-32-bit.exe)) make sure git is installed by 
```bash
git --version 
```
then configure your email and username (change your username and email )
```bash
git config --global user.name  Gdahboy 
git config --global user.email abderrahim.gdah@esprit.tn 
```
2.first commit 
now jump to your code repository and type : 
```bash
git init 
```
![](https://i.imgur.com/bzvle8q.jpg)
now we will have 3 repo : your working directory (represented in blue in image ) , Staging area (brown) , Local respository (green) they are all logical Repository of course . indeed they represent the lifecycle of working with git. every file exists in Blue , if you add the file you tell git that you want to keep tracking the file , so every modification will be saved in brown and if you commit that change this modification will remain forever and you could get it back whenever you want , because it will be saved in green .  Purple (purple repository ) represent github , gitlab ... where all the folder will be saved . 
enough talk , let's commit something !!! 
sorry , i need to remeber you first we need to add file in order to commit 
```bash
git add file.c file.txt ...
```
and finally !!!! 
```bash
git commit -m "first commit" 
```
so far , everything is great . but how could we know if a file is addes or not or if git is tracking the changes that we want , it is even easier than we think
```bash
git status 
```
![](https://i.imgur.com/0WkxfPT.png)
again one more time, even if we add a file to stage area (brown repo) and we commit the file, every change that come after the commit , before to commit the change again you need to add the file first !!! 
3.display all commit 
```bash
git log 
```
or for less information 
```bash
git log --pretty=one 
```
![](https://i.imgur.com/T8ZXfLM.png)
4.back in time !! 
now if we want to go back in time in our code we can do 
```bash
git revert c7aaab7e8efdb750da70a535fb393d1329173bf5
```
(c7aaab7e...) of course this is the id of random commit you need to change that with the id of commit you like (you can get the id from git log ) 
1. let's build a branch 
so, what if we go back in code and we find something different and you have 2 idea . so you can create branch from old commit that inheret all the code from that commit . 
```bash
git branch NameOfBranch
```
6. navigate between branch  
```bash
git checkout NameOfBranch
```
7. submit your code to github 
```bash
git push origin master
```
Conclusion 
so to resume, we need to add the file to keep track of it, then commit it, new idea we will have new branch of course git have a lot more feature, we didn't even cover 10% of it's features (that we will do next article ). finally i find this on web, i really like it. it will help you a lot and will introduce for you many new concepts please don't hesitate to text me anytime . 
![](https://i.imgur.com/NcWcpbn.jpg)