A beginner's guide to Git

What is Version Control System?

A Version Control System (VCS) also known as Source Code Manager (SCM) is a system that records changes to a file or set of files over time so that you can recall specific versions later. So ideally, we can place any file in the computer on version control.

So, what is Git?

Git is a version-control system for tracking changes in computer files and coordinating work on those files among multiple people. Git is a Distributed Version Control System.

It helps you keep track of the changes you make to your code. It is basically the history tab for your code editor. If at any point while coding you hit a fatal error and don’t know what’s causing it you can always revert back to the stable state. So it is very helpful for debugging. Or you can simply see what changes you made to your code over time.

By using services like GitHub, GitLab, BitBucket etc multiple people and teams can easily collaborate among themselves on various projects and with help of Git can easily track all the changes along the code base.

Common terminologies to get familiar with

Repository

A repository aka repo is nothing but a collection of source code. It contains all of your project's files and each file's revision history with commits. You can discuss and manage your project's work within the repository. Repositories can be owned individually, or in a shared ownership with other people in an organization.

Branch

A branch is a version of the repository that diverges from the main working project, it is like branch of tree. It is an essential feature available in most modern version control systems. A Git project can have more than one branch. We can perform many operations on Git branch-like rename, list, delete, etc. The default branch in Git is the Master or the Main branch.

Master

Master or Main is a naming convention for Git branch. It's a default branch of Git. After cloning a project from a remote server, the resulting local repository contains only a single local branch. This branch is called a "master" branch. It means that "master" is a repository's "default" branch.

Commit

Every time you 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. All the changes from removing to adding code base all are noted via perticular commit.

Some of the important Git commands

git init

git init is the git command by which we can create a new git repository from scratch. It is also used to initialize the existing project folder as a git repository.

git add

git add is a command used to add a file that is in the working directory to the staging area.

git status

git status is a command used to see what you have in the staging area and ready for commit, basically it will display the difference between "git add" and "git commit" command

git commit

git commit is a command used to add all files that are staged to the local repository.

git push

git push is a command used to push the local repository into the remote repository services such as GitHub, GitLab, etc.

git pull

git pull is a command used to pull the remote repository from services like GitHub, to the local working directory.

git clone

git clone is a command used to download and setup a remote repository into the local environment.

git merge

git merge is a command used to to get the files from the local repository into the working directory.