Introduction to version control and Git

Nirasha Jayasiri
5 min readMar 9, 2022

In this article, I am going to cover these topics.

· What is version control?

· Why version control is so important?

· Types of version control systems

· Git

· Git and Version controlling terminology

· Basic Git commands

What is version control?

Version control is the process of tracking and managing changes to files over time. This helps to protect the source code from permanent harm. When using a version control system, it identifies all changes using a revision number and tracks the timestamp of the modification, addition, or deletion as well as the person who is responsible for that change. All revisions can be compared and if the current code has conflicts, it can easily be restored to a previous stage. This enables developers the freedom to correct their mistakes without affecting others’ work and do experiments on the code.

Why version control is so important?

Let’s discuss some benefits and importance of using version control.

· Enables teams to collaborate and streamline development to resolve conflicts.

· Facilitates coordination, sharing, and collaboration across the entire software development team.

· Makes it easier to maintain the development of large projects.

· Provides an environment for teams to review and comment on each other’s code and improve their skills.

· Fasten the process of merging commits and accelerates the delivery of the software product.

· Easy development of different versions of the software product.

· Improves the visibility of the code.

· Higher traceability

· Allows team members to work on the same files concurrently without affecting others’ work.

· Reduces redundancies and helps to detect errors earlier.

· Allows manager or the leader to review and track the status of the development of a software product.

· Version controlling provides a secure way for software configuration management.

Types of version control systems

There are two main categories of version control systems.

Centralized version control systems

source:- https://www.geeksforgeeks.org/version-control-systems/

The main concept of a centralized version control system is that it works in a client and server relationship. The repository is located in one place and provides access to many clients. All changes, users, commits, and information must be sent and received from this central repository.

Advantages of using a centralized version control system are it is easy to understand and has more control over users and access.

Disadvantages are it is hard to manage servers and backups and it can be slower because every command connects to the server.

Ex: Subversion

Distributed version control systems

source:- https://www.geeksforgeeks.org/version-control-systems/

In distributed version control, each user has their own copy of the entire repository, not just the files but the history as well. It is like a network of individual repositories.

These systems are more powerful and have fewer conflicts. No servers are needed and branching, and merging is more reliable. These systems are faster than centralized version control systems.

These distributed version control systems have some drawbacks too. This model is harder to understand, and revisions are not in the incremental numbers which makes it harder to reference.

The most popular distributed version control system is Git. Mercurial is also a distributed version control system.

Let’s discuss about Git.

Git

source:- https://git-scm.com/downloads/logos

Git stands for Global Information Tracker. Git is the most popular version control system, and it is free and open source. It is used for software projects of any size, making it a popular option for startups, enterprises, and everything in between. Git supports multiple protocols such as HTTP and SSH.

Click here to Download git

But there are some drawbacks of Git too. Git lacks security. It’s impossible to scale.

Git and Version controlling terminology

Repository

A repository is a central location where all the files are being kept. Usually, a directory with a set of files. Repositories can exist either locally on your computer or as a remote copy on another computer. A repository is made up of commits.

Trunk

This is where the most stable code is being placed which is referred to as the production code.

Stage

Mark files for tracking changes.

Staging area/ index

It is a file in the Git repository that stores information about what will go into the next commit.

Commit

When committing it takes a snapshot of what all the files look like at the moment and store a reference to that.

Branch

It is a copy of the master branch taken at a given point. All the feature developments and bug fixes will be done in a branch. Usually, it is allowed to have multiple branches at the same time. This alternative line of development can continue without altering the mainline.

Merge

Merge means combining branches together to update the master branch.

Checkout

It marks/unlocks a file for changing. A checkout is when the content in the repository has been copied to the Working Directory.

Merge conflict

Merge conflicts occur when merging a file that has been changed in two separate branches or places. Changes that interfere with other changes.

Mainline

This is similar to trunk but, there can be a mainline for each branch.

Clone

Cloning means creating a repository containing the revisions from another repository.

Initialize

Creating a new empty repository.

Pull & push

Copy revisions from one repository to another.

Pull request

Asking others to merge their pushed changes.

Tag

A tag or label refers to an important snapshot in time, consistent across many files. These files at that point may all be tagged with a user-friendly, meaningful name or revision number. — Wikipedia

Basic Git commands

let’s discuss some of the basic git commands.

git init

Create a new local repository

git clone
Create a working copy of a local repository: git clone /path/to/repository

If it is a remote server: git clone username@host:/path/to/repository

git add

Add one or more files to the staging

git commit

Commit changes to head but not yet to the remote repository.

git commit – m “message”

git push origin master

Send changes to the master branch of your remote repository

git status

List the files you have changed and those still need to add or commit

git checkout -b <branchname>

create a new branch and switch to it

git push --all origin

push all branches to the remote repository

git pull

fetch and merge changes on the remote server to your working directory

Conclusion

In this article, I have presented version control, the importance, and benefits of version control, types of version control systems, and Git as a widely used distributed version control system.

--

--