Git is a distributed version control for tracking changes and to maintain multiple versions of code during the development of a software project. To understand Git, we should understand version control.
A version control a.k.a source control a.k.a revision control is an application that helps to maintain versions of a code. Before we continue any further, we must know some important terms that will be used while we study version control:-
- Repository: A repository is a place to store the code and other files created and modified during the development of the application. A repository also maintains the history of the code and other files generated during the development of the program.
- Trunk: Trunk is the master branch of the git repository. That is, it is the main development line of the repository. All the branches merged will at last merge with this line to form the main line.
- Tags: Tag is a descriptive name given to a specific version of the project. It forms as an memorable alternative to the id generated by version control.
- Branch: A branch generates multiple development lines for the repository. This feature helps when there are multiple people working on the same project.
- pull: Pulling is the process of downloading recent changes from the central repository to the computer’s local repository. If the repository is being downloaded for the first time, it is called cloning.
- Pushing: Pushing is the process of uploading all the changes into the central server.
- Committing: Committing is the process through which the version control records and stores changes to the central repository. The committing process also helps to document the changes done by the developer.
That is, each change in the program’s code can be recorded during the development of the application. The major advantages of version control are:-
- If the developer’s recent change has crashed, he/she can revert back to his previous versions.
- A developer can compare different versions of his code for bug fixing, release documentation and many more purposes.
- Version control helps in efficient usage team members during development of group projects as multiple developers can contribute to the project. Each developer can track changes done by each developer to the project.
- Version control supports branching, a method to create multiple workflow that doesn’t affect the master branch. The developer can also merge these multiple branches to the master line.
- Acts as a backup for the code.
A version control works on the principle of graph data structure. That is, each change recorded during commit forms a node in the graph data structure.
The above image is self explanatory on how version’s branching and merging works using graph data structure.
Types of Version Control
The types of version control are:-
- Local version control
- Centralized version control
- Distributed version control
A local version control maintains versions of the code on the local computer. One of the most common methods of maintaining versions is local version control. The versions are maintained as different files. Due to this methodology, there is a great chance for accidental loss of data due to accidental changes to the wrong file.
A centralized version control is a version control approach through which different versions of the code are maintained on a centralized server. A centralized version control can store versions of code and has a list of user’s who has the privilege to access the repository (Central code). An example of centralized version control is Tortoise SVN.
A distributed version control is a type of version control system that helps to clone the repository in which the code is present along with it’s full history. The main advantage of this method is that, if any of the central servers fails, the developer can restore the repository by uploading (pushing) the code to the server. That is, a distributed version control creates a complete backup of the repository into the local computer. An example of distributed version control is git.
The popular version systems are:-
- SVN (Apache Subversion)
What is Git?
Git is distributed version control application that comes under General Public License 2 (GPL 2). Git was developed by Linus Torvalds during the development of Linux kernel in 2005. As git comes under distributed version control, the local repository of projects developed using git will have complete history of changes irrespective of internet access or access to the server. Git is developed using C, Python, TCL,Perl and Shell.
Ubuntu / Debian
$ sudo apt install git-all
$ sudo dnf install git-all
Centos / RHEL
$ sudo yum install git-all
You can install git using brew package manager as follows.
$ brew install git
Or, you can install as follows:-
- Download git for mac from this link.
- Execute the installer and follow the steps to install git into mac.
But, I would prefer to use brew because you can update the application easily by just executing
- Download git for windows using this link.
- Execute the installer and follow the steps to install git into windows.