Before talking about Git, let’s define what is version control. It is a system that records changes to a file or set of files over time so that you can recall specific versions later. Git was created by Linux kernel and it is a distributed version control system, originally designed for coordinating work among software engineers cooperating on source code during software development.
In complex projects, where multiple people might be making changes to the same files simultaneously, it’s easy to get into a weird state. When you edit a file, git can help you determine exactly what changed, who changed it and why.
GitHub is not git. May git newbies confuse the two. GitHub is a web application for hosting projects that use git. After installing git you can start your own repository (in any existing directory on your machine).
This will create a hidden .git directory which contains internal tracking data of a repository (file changes).
If everybody was working on the same copy of the directory, it would be a mess. Git provides a powerful feature called branch. Think of it like creating a copy of your working directory and giving it to another developer. Now, another developer can work on a separate copy without having conflicts with yours. Below this command creates a new branch from the current branch and switches to it immediately.
If your repository has multiple branches, you can navigate between them. Below we switch to the main branch. Checking out a branch updates the files in the working directory to match the version stored in that branch.
You can also clone (basically download) a .git repository to your machine and extract the latest snapshot of the repository to your working directory.