Version Control and Git

Hasini Sandunika Silva
4 min readMay 15, 2021

--

Version Control and Git

Git is a distributed revision control and source code management system initially designed and developed by Linus Torvalds.

Version Control System (VCS)

This helps developers to work together (even in remote) and maintain a complete history of their work. There are 2 types of version controls;

  • Centralized version control system (CVCS):

This uses a central server to store all files and enables team collaboration. But the problem with this is, a single point of failure can cause restrict access to the remote server for a moment. The other problem with this is, if a disk of the central server gets corrupted, due to lack of proper backup, the contributors of the project will lose the entire history of the project. To address these problems Distributed Version Control System (DVCS) came into the picture.

  • Distributed Version Control System (DVCS):

Here user also keeps a copy of the repository therefore she or he can perform many operations when they are offline. If the server goes down, the things in the client repositories can be copied back to the remote server after fixing it. Git, Mercurial, Bazaar are some of the examples of the distributed version control system. Refer to figure 1.

Figure 1. The Architecture of the Git.

GitHub, Bitbucket, and GitLab are remote online hosts that are used to perform version control with the help of git.

Usually, Git operations can be performed through the IDE, Git Bash, SourceTree, Git GUI, etc.

Some Terminologies in Git

  • Branch: A version created from the main repository.
  • Checkout: Switching from one branch to another branch.
  • Clone: Creates a copy of the target repository.
  • HEAD: represents the last commit in the current checkout branch.
  • Master: Default branch in git.
  • Merge: Integrates branches into a single branch.
  • Origin: refers to the remote repository.
  • Fetch: Fetches branches and tags from one or more other repositories.
  • Pull: Used to receive the data from the remote repository.
  • Push: Uploads locally committed repository content to the remote repository.
  • Remote: Defines the remote repository.
  • Stashing: Enables to switch to another branch without committing.
  • Tag: Used to mark commits stage as important. (creates tags when releasing a version).
  • Git revert: Reverts (undo) the commits.
  • Git ignore: Used to specify intentionally untracked files that Git should ignore.
  • Git squash: Used to squash previous commits into one.
  • Git Fork: Used to create a rough copy of the repository.

Git Flow

There are different types of branches in a project.

  • Main branches

Master and develop branches are considered the main branches of the project. The master branch defines the final versions of the project and this is used to tag the versions of the project. Develop branch is parallel to the master branch and this is considered as the main active branch throughout the project. Develop branch includes the final source code for the release and when it reaches a stable point the development branch should be merged with the master branch and add the tag with the release version.

  • Supportive branches

Feature, release, hotfix branches are considered supportive branches. These are only creating for a limited time and these will be removed after making use of them. The feature branch is created only for the development purpose and after merging this with the develop branch, the feature branch will be deleted by the developer. The release branch is used to manage QA releases. After fixing the bugs during the QA process this branch can be merged with the develop branch. Hotfix branches are similar to release branches. These are created when there is a critical bug in a production version. After fixing the bug, the hotfix branch can be merged with the master branch with a tag.

Figure 2 shows the general flow of Git.

Figure 2. Git Flow.

The following defines some of the commands that are used to perform operations in Git. (Refer to figure 3).

Figure 3. Git Commands.

Conclusions

  • Git is a Distributed Version Control System.
  • There are predefined commands to perform Git operations.
  • Mainly there are 2 types of branches in Git called main and supportive branches.

References

--

--

Hasini Sandunika Silva
Hasini Sandunika Silva

No responses yet