DEV Community

Cover image for Version Control(Git) for Beginners
Vadim Kolobanov for Abstract

Posted on • Updated on • Originally published at dev.to

Version Control(Git) for Beginners

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

Centrilized VCS

Centralized VCS

Distributed VCS

Distributed VCS

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

Diffs

snap(delta)

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

Git configuration

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
Enter fullscreen mode Exit fullscreen mode

Help

$ git help [command]
$ man git-<verb> //Linux command
$ git <verb> -h | --help
Enter fullscreen mode Exit fullscreen mode

Getting started

$ git init
$ git clone https://github.com/username/repo
Enter fullscreen mode Exit fullscreen mode

File lifecycle

Lifecycle

Adding to staging

Add changes to staging
$ git add []

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 []

Saving the changes. Commit

Move a file from staged to modified
$ git reset HEAD

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

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

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

My Twitter

Become a patron

Top comments (0)