Version Control(Git) for Beginners
Tags: git, beginners, programming, tutorial
Published: 2021-11-02 12:56:34

##What is VCS

**VCS** – version control system.
A version control system is a system that records changes to a file or set of files over time and allows you to return later to a specific version.

##Types of VCS

* Local (RCS)
* Centralized (CVS, Subversion)
* Distributed (Git, Mercurial, BitKeeper)

###Local VCS

![Local VCS](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6kedh6od0gqncxl9b322.png)
 
###Centrilized VCS

![Centralized VCS](http://xinyeshuaiqi.cn/wp-content/uploads/2019/01/3.jpg)

###Distributed VCS

![Distributed VCS](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/r73arm5tdzfq3qp5i4yg.png)
 
##Advantages of GIT

* Speed.
* Simple design.
* Strong support for non-linear development (thousands of parallel branches).
* Fully distributed.
* Able to handle large projects like the Linux kernel efficiently (speed and data size).

###Basic ideas

* Versions are snapshots, not diff.
* Almost all operations are performed locally
* Integrity. The SHA-1 hash is calculated for everything.
* After adding data to the git, it is hard (but possible) to lose them.
* Full git support is available only in the terminal.
* All files can be in one of the following states - committed, modified, staged

###Changes are snapshots not a difference


**Shapshots**

![Snapshots](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qogtkmu4csw0xscp5vff.png)
 

**Diffs**

![snap(delta)](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3n6aktrugcflb9mqrel2.png)
 

Each project file in Git/Mercurial indexing process can have one of the three possible states:

* **modified, but not staged:** This is when a project file is modified by the user, but Git/Mercurial has no track of the file changes at the moment. If the file is lost or removed unexpectedly, then Git cannot recover the file.

* **staged for commit to the repository:** When a file is modified it can be added to the Git staging area to be later committed permanently to the repository. The staging area is a file, generally contained in the project’s repository ( directory), that stores information about what will go into the next commit to the repository. The staging area is also sometimes referred to as the index. .git

* **committed to the repository:** Once the staged files are committed to the repository, they become a permanent part of it, and can be later extracted (checked out) for review or further development.
These three file states comprise an important integral part of Git and Mercurial. The following figure provides an illustration of the three file states.

![Stages](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1emw55gmk6tv22g4vkou.png)
 
###Git configuration

```terminal
git config [--<layer>]  <key>

layers:
 --system 
 --global  
 --local 
$ git config --global user.name "Vadim Kolobanov"
$ git config --global user.email titanyforgame@gmail.com
$ git config --global core.editor nano
$ git config --global credential.helper store
```

###Help

```terminal
$ git help [command]
$ man git-<verb> //Linux command
$ git <verb> -h | --help
```

###Getting started

```terminal
$ git init
$ git clone https://github.com/username/repo
```

###File lifecycle

![Lifecycle](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/iwzxyyyiy1cekmmlm8de.png)
 
###Adding to staging

Add changes to staging
$ git add <filename> [<filename>]

You can use wildcards:

$ git add *.py

`.` - is used to add all changes:

$ git add .

*- to replace any string of asterisk characters
`?` - to replace any single character with a question mark.

###Viewing GIT status

Current status (changes, branch)
$ git status

Command Parameters:
$ git status --help

View file changes:
$ git diff [<filename>]

###Saving the changes. Commit

Move a file from staged to modified
$ git reset HEAD <filename>

Move the file to the unchanged state. (Undo all changes):
$ git checkout -- <filename>

Delete a file from the working directory.
--cached to mark for deletion but not physically delete:
$ git rm [ --cached] <filename>

Add changes from staging to the last commit:
$ git commit --amend

###Viewing history

$ git log

commit 5f5b7b4b1e1684a9b428dce1bfcf86085ccf4b6f (HEAD -> issue-1)
Author: Some_User <somemail@gmail.com>
Date:   Mon Nov 01 22:11:19 2021 +0300
20

Add view for GET user credentials

commit ac1b0e4a0613fab175a7a99858e128d17412fbf3 (origin/issue-1)
Author: Some_User <somemail@gmail.com>
Date:   Mon Nov 01 23:49:19 2021 +0300

Add db settings


### PS

**This is basic information about git, additionally in the next part I will tell you about branches, merges, remote repositories. Good luck to everyone in learning**


[Write me on Face....oh...Meta](https://www.facebook.com/neo.skarynsky)

[My Twitter](https://twitter.com/decodesperato)

<a href="https://www.patreon.com/bePatron?u=64009903" data-patreon-widget-type="become-patron-button"><img src="https://res.cloudinary.com/practicaldev/image/fetch/s--4kAQAgAW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/db3jtgy2i5l4w8slkps5.png" alt="Become a patron" loading="lazy"></a><script asyncsrc="https://c6.patreon.com/becomePatronButton.bundle.js"></script>