Learn the Basics of Git

Let’s get started!

What is Version Control?

Version control 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.

Git also helps you synchronize code between multiple people. So imagine you and your friend collaborating on a project. You both are working on the same project files. Now Git takes those changes you and your friend made independently and merges them into a single “master” repository.

What is a Repository?

A repository (repo) is nothing but a collection of source code.

There are four fundamental elements in the Git Workflow.

  • Working Directory
  • Staging Area
  • Local Repository
  • Remote Repository

Diagram of a simple Git Workflow

pic.png

If you consider a file in your Working Directory, it can be in three possible states.

Let’s get started!

  • It can be staged => This means the files with the updated changes are marked to be committed to the local repository but not yet committed.
  • It can be modified => This means the files with the updated changes are not yet stored in the local repository.
  • It can be committed => This means that the changes you made to your file are safely stored in the local repository.

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

  • git commit is a command used to add all files that are staged to the local repository and also put the about what you have done
  • git push is a command used to add all committed files in the local repository to the remote repository, So in the remote repository, all files and changes will be visible to anyone with access to the remote repository.
  • git fetch is a command used to get files from the remote repository to the local repository but not into the working directory.
  • git merge is a command used to get the files from the local repository into the working directory
  • git pull is a command used to get files from the remote repository directly into the working directory, It is equivalent to a git fetch and a git merge.