Git, source control, GitHub and hosting
Published: 2023-07-05 11:36:44

# Version control system (VCS)

### What is version control system?

You can think of a Version Control System (aka VCS) as a kind of database. It lets you save snaphot of the complete project at any point in time.

- Who made the change
- Why the change was made (references to problems fixed or features added in change)

Later when it is required to take a look at on older snaphot/version, VCS shows how exactly it differed from the previous one.

Version Control System (VCS) are tools that help teams manage and track changes in code over time.

## Why Version Control system is needed?

### 1. Collaboration

if the developers word on a same project from different regions, it will be hard for them collaborate without the version control system.

### 2. Storing Version

Managing multiple versions of a project in your disk can be challenging as required storing and organizing a potentially large amount of data. 

### 3. Restoring Previous Version

Version control systems offer the ability to roll back to a previous version if needed or issue is inteoduced, developers can revert to a known working state of the project.

### 4. Backup

In case system or disk of the user braks down and there is no backup all the files will be lost hense version control system shoud be used

## Types of version control system

- **Local Version Control System**

![Untitled](https://s3-us-west-2.amazonaws.com/secure.notion-static.com/654db9b7-b2a8-4bb2-82ee-969bffa29d4d/Untitled.png)

- **Centralized  Version Control System**

![Untitled](https://s3-us-west-2.amazonaws.com/secure.notion-static.com/dbab3a91-df2d-4830-91ba-63f184b4a9a7/Untitled.png)

- **Distributed Version Control System**

![Untitled](https://s3-us-west-2.amazonaws.com/secure.notion-static.com/e5e21119-148f-4464-b922-6171b2d0eabf/Untitled.png)

# What is Git?

- Git is a distributed version control system widely used in software development.
- It allows multiple developers to work collaboratively on a project.
- Can effectively manage and track changes to the source code.

Git stores its data in a series of snapshots of a miniature filesystem. Every time you commit a change or save your project state, Git takes a snapshot of all your files at that moment and stores a reference to that snapshot.

A Git project resides in three sections:

**The Working Directory.** The single checkout of one version of the project. 

**The Staging Area**. An index that stores information about what the next commit will contain. 

**The Git Repository**. The place where Git stores the metadata and object database for a project.

### How to push code to GitHub using Terminal

1. **git init** - To initialize a repository, Git creates a hidden directory called .git. That directory store all of the objecs and refs that Git uses.
2. **git add** - single file (filename) all files (.) 
3. **git commit -m “message”** - this command captures a snaphot of the project’s currently staged changes and saves the commit message.
4. **git branch** -M main - creates a new branch “main”
5. git remote add origin (url) - When you execute the command, you are specifying the URL of remote repository you want to connect to and giving it the name “origin.”
6. **git push -u origin main** - The commend “git push -u origin main” is used in Git to push the local branch “main” to the remote repository named “origin”

![Untitled](https://s3-us-west-2.amazonaws.com/secure.notion-static.com/103a722c-7a0a-469c-8191-644cf8ae9fe6/Untitled.png)

![Untitled](https://s3-us-west-2.amazonaws.com/secure.notion-static.com/1bbfc87e-d17e-4834-94af-5aa44be74a3f/Untitled.png)

### How to push updated code to GitHub using Terminal

1. `git add .`
2. `git commit -m "first commit"`
3. `git push`

cd \file path