Git and GitHub - The Version Control System

Have you ever wondered how multiple teams collaborate on a project? Or what happens if we want to check the history of a file in our codebase? Or how are different versions of an application managed?

In this article, we are going to understand what is a version control system, and how is it used to manage codebases for different projects. We are also going to look at what are Git and GitHub, and how are they useful for teams collaborating on a single codebase.

Introduction

Version Control System is a very essential part of any project with code. Whether you are creating a simple Calendar Mobile App or building a Real-Time Web Dashboard, you need to manage and track the changes taking place within your programs. We can take the example of the bank balance — it is not just sufficient to have your final account balance, but it is also important to have a history of transactions for proper accounting. This record of transactions also helps you to identify fraud or file for wrong transfers. Similarly, having a history of a file in the source code helps in determining the point at which an error (or a bug) occurred and who was responsible for those changes.

Git today is the most popular version control system used by developers across the world. And GitHub is one of the most popular platforms that provide Remote Hosting Services for Git. Git can be installed in our systems, and we can use it locally to manage the versions of our project, while GitHub provides a web interface to manage these Git repositories (source code) including some additional features.

convert.jpg

Photo by Devon Janse van Rensburg on Unsplash

Terminologies

Let us get familiar with some of the techy terms that we are going to use in the rest of the article.

Repositories (Repo)

A git repository refers to the source code, along with its history of changes and metadata. This is stored within a folder named “.git/” in the root(top-most folder) of your project directory.

Commits

The changes to the files can be saved in batches, and committing these changes refers to the process of saving the set of changes to the repository history. These different batches can be called commits.

Branches

We can choose to create multiple snapshots of the source code at different times and start working on those snapshots individually. These snapshots are called branches, and there is always one primary branch for one repository where generally the latest and most stable code is stored. To understand it better think of 2 developers collaborating on two different features of the same app. They can create two different branches, work on their individual features in the respective branch, and then merge those branches into the primary(main) branch.

Push and Pull

When it comes to remote repositories, we can use Push and Pull commands to sync our changes with the remote branch. For example, when we have made some changes, we can use the push command to send our changes to the remote repository, while if some other member of the team has made a change and pushed it to the remote repo, we can use the pull command to get those changes on our local system.

convert.jpg

Photo by Glenn Carstens-Peters on Unsplash

Remote Repository

One can ask “ Why do we need a remote repo like Github, and why can't we just collaborate locally with Git itself?”

One of the most important reasons for using cloud/remote repos is Collaboration with team members. Suppose, I am living in India, and my team member with whom I am working on a project lives in France, then we will not be able to share our local repositories. We will need a cloud-based or remote repo, which we can share and access.

The second reason to use a remote repository is the Durability of the source code. Imagine I am working on an application for months, and I am using Git locally for my version control. It has been going great, but one day, my laptop gets crushed by a gain rock (or maybe just gets infected by a virus), and all my files are gone. Now, what will I do? If I had maintained my repo on a remote system, the chances of my codebase being gone are very very low.

convert.jpg

Photo by krakenimages on Unsplash

Examples

Let us have a look at some examples of where we can use version control to make our lives easier.

Mobile Application Versions

I am sure that at some point in time, you have to update your mobile apps by going to PlayStore or App Store or setting up an automatic update. Whenever an app releases a new version of an application that might not be compatible with older versions of Android and IOS, it maintains an old version that was compatible with these older OS versions. This history is maintained and tracked using the version control systems.

Open Source Contributions

Most of the open-source software and packages are hosted on GitHub, where thousands of different can contribute to some part of the project. To manage such a huge scale of collaborators, it is necessary to maintain a proper track of changes made by different contributors.

Error Management

Suppose, you and your team are working on a web application that trades stocks in real-time using a strategy. And when you pull the latest changes made by your teammates in the morning, and test them, you notice, that your strategy that used to yield a 17% return is now showing 98% losses. You can go to the history in Git/Github, and check which change made by which one of your teammates caused this excellent transition. And if needed, you can revert to a previous commit to undo these changes.

Conclusion

Version Control is one of the most essential skills that a developer needs throughout his career. It is largely used in deployment, integration, and distribution. Almost every single organization that has anything to do with code is using some kind of version control and enjoys the several advantages that come with it.

I hope you enjoyed reading the post. To follow up with the new articles, follow me on Medium, or subscribe to my Newsletter at the bottom of the page.

Leave a Reply

Related Posts

Categories

Subscribe To The Newsletter

To reach us out, contact us on [email protected]
or check out our linkedin page
© Copyright 2024, Thinkfeed. All rights reserved.
Read the privacy policy and terms of service.