Git for Beginners
Tags: github, git, beginners, codenewbie
Published: 2020-11-21 12:12:04

If you guys quickly search on **Google** about **Git** it says that
> "Git is a distributed version-control system for tracking changes in source code during software development." 

So, What is a Version Control System?
&nbsp;&nbsp;&nbsp;&nbsp; First thing first, try reading "version control" as "control version". A **Version Control System (VCS)** or also called as **Source Code Manager (SCM)** is just software that helps you control (or manage) the different versions of something (typically your Source Code). 
&nbsp;&nbsp;&nbsp;&nbsp; **Git** is an **SCM** (and therefore a **VCS**!). The URL for the Git website is "https://git-scm.com/" (and you can see how it has "SCM" directly in its domain!).

There are a lot of Version Control Systems:
1. SVN
2. GIT 
3. Mercurial
4. Bazaar

But, there are two main types of Version Control Systems:
* The **Centralized Model** - where, all Users connect to a central, master repository.
* The **Distributed Model** - where, each User has the entire repository on their computer.

### Git Terminologies / Keywords :

1. **Repository / Repo**: <br>
A Repository is a directory(folder) which contains your project work, which are used to communicate with Git. Repositories can exist either locally on your computer or as a remote copy on another computer. A repository is made up of commits.

2. **Commit**:<br>
Every time you save (commit) the state of your project in Git, it basically takes a picture of what all your files look like at that moment and stores a reference to that commit. You can think of it as a save point in a game - it saves your project's files and any information about them.

3. **Working Directory**:<br>
The Working Directory(Folder) are the files that you see in your computer's file system. When you open your project files on a code editor, you're working with files in the Working Directory. This is in contrast to the files that have been saved (in commits) in the repository.

4. **Branch**:<br>
Branch in Git is similar to the branch of a tree. Going back to the example of save point in a game, you can think of a branch as where you make a save point in your game and then decide to try out a risky move in the game. If the risky move doesn't pan out, then you can just go back to the save point. The key thing that makes branches incredibly powerful is that you can make save points on one branch, and then switch to a different branch and make save points there, too.
The Primary(default) branch in Git is the **Master** or the **Main** branch.

5. **Staging Area / Staging Index / Index**:<br>
A file in the Git directory that stores information about what will go into your next commit. You can think of the staging area as a prep table where Git will take the next commit. Files on the Staging Index are poised to be added to the repository.

### Some of the Basic but Important Commands of Git:

1. **git init**:<br>
Running this command will create a **new git repository** from scratch. It is also used to **initialize the existing project folder** as a **git repository**.
Example: `git init`

2. **git add <file>**:<br>
This command will add the file or files that u specify to the staging area or the index. You can run this command as many times as you need. But, Remember **before commiting the files it will keep in the staging area**. Instead of listing all file names one by one, you can use "." after "git add" to select all files under the current directory. 
Example: `git add filename` or `git add .`

3. **git status**:<br>
If you want to see what you have in the Staging Area and ready for commit you can run the command. It will display paths of your tracked and untracked files.So, basically it will display the difference between "git add" and "git commit" command.But, Remember it will not show any commit records or information.
Example: `git status`

4. **git commit**:<br>
This command will take everything that is in the index for the Staging area and put it into the local repository.The "-m" option, which stands for "message". Writing good commit messages is a skill.
Example: `git commit -m "Add files"`

5. **git push**:<br>
When you run this command it will take your local repository that you have created and then push it to the remote repository such as **Github**.
Example: `git push <remote> <branch>`

6. **git pull**:<br>
If you want to pull the latest changes from the remote repository  to the local repository you can do it using git pull command. This command is mostly useful when you are working in a Team or an Organisation.
Example: `git pull <remote>`

7. **git clone**:<br>
The git clone command download the existing remote repository on your local computer by specifying the URL of the remote repository.Basically, If you find a program or project that you like on GitHub you can clone it and that will download it in your machine.
Example: `git clone https://github.com/userName/repositoryName.git`

Let me know what you think about this article, and Git in general. I hope this guide will help you with your learning, and hopefully save your time ? **Thank you**