DEV Community

Cover image for Understanding Git: The Ultimate Guide with Practical Examples
Jahid Hiron
Jahid Hiron

Posted on

Understanding Git: The Ultimate Guide with Practical Examples

Git is a powerful tool for managing versions in software development. It works like a digital filing system, allowing you to store multiple versions of your work and easily revert to an earlier version if needed.

One great advantage of Git is that it's distributed, meaning each developer has a complete copy of the project, including its history, on their computer. This makes it easy for teams to collaborate, no matter where they’re located

In this guide, I’ll explain the fundamentals of Git and why it’s helpful for anyone managing code or files. By the end, you'll clearly understand what Git is and how it can enhance your project workflow.

Linus Torvalds, the creator of Linux, also developed Git. He built Git to manage contributions from different developers while working on the Linux Kernel project.

If you visit Git's official website, you'll find the definition that "Git is a free and open-source distributed version control system".



Image description

I know the definition might seem complicated. There are two important terms here: distributed and version control system. Let’s begin by explaining a version control system.

A Version Control System (VCS) is a tool that keeps track of changes to files. It allows you to go back to earlier versions of a file or group of files whenever you need. With Git, you can easily undo changes and get back to previous versions of your work.

Git isn’t limited to tracking just source code—it can also manage images, research papers, or any type of file.



There are three types of version control systems:

  1. Local version control system
  2. Centralized version control system
  3. Distributed version control system



A Local Version Control System is an easy way to keep track of file changes. You save copies of your files in different folders or directories, usually by date or version. It's like making a backup every time you change something.

For example, imagine you're working on a document. Each time you make an update, you save a new version in a folder labeled with a version number or timestamp, such as Version_1 or Version_1_YYYYMMDD_HHMM. If anything goes wrong or you want to review an earlier version, you can quickly revert to one of these copies.



Image description

Local version control comes with several significant limitations that impact its efficiency and usability:

  1. Limited Accessibility: These systems are only accessible on your local machine, making collaboration difficult. Sharing files requires manual methods, such as email or external drives.
  2. No Backup: Since everything is stored locally if your machine is lost or damaged, you can only recover versions and backups if you’ve made manual external backups.
  3. No Collaboration Features: Multiple people cannot simultaneously work on the same project. If one person makes changes, they may accidentally overwrite another’s work, resulting in conflicts.
  4. Manual Versioning: Users must manually create new folders or files for each version, which can lead to mistakes, such as forgetting to save a new version, accidentally overwriting files, or mislabeling them.



A Centralized Version Control System was developed to facilitate developer collaboration. In this setup, all versioned files are stored on a single server, which allows multiple users to access them from one central location. This approach is similar to a local version control system, but everything is stored on the server instead of saving files and backups on individual machines.

This approach has been widely used for version control for many years, helping teams collaborate on their projects. Some examples of centralized version control systems are Subversion (SVN), CVS (Concurrent Versions System), Microsoft Team Foundation Server (TFS), and Perforce.



Image description

Centralized version control systems provide a different way to manage file versions than local version control systems. They improve collaboration and organize changes but also have their benefits and drawbacks. Here are the pros and cons:

Pros:

  1. Enhanced Collaboration: Multiple users can work on the same project simultaneously, accessing a single source for all files.
  2. Simplified Backup: All files are kept on a central server, which simplifies backing up the entire project and helps keep track of different versions.
  3. Version History: Centralized systems keep a complete record of all changes, making it easy to track edits and return to earlier versions.

Cons:

  1. Single Point of Failure: If the central server goes down, users cannot access their versioned files until the server is back up and running.
  2. Network Dependency: Users need an internet connection to access the file system, which can slow down work when they are offline.
  3. Potential for Conflicts: When multiple users make changes simultaneously, it can create conflicts that need to be fixed manually.



A Distributed Version Control System allows users to access files and have copies of the entire project, including its history. Unlike centralized version control systems, which give users only one version of the files at a time without any history, a distributed version control system records every modification along with its date and time, providing a detailed history of changes.



Image description

Distributed version control systems offer several advantages over centralized version control systems, enhancing collaboration and project management. Here are some key benefits:

  1. Independent Work: Users can work offline and make changes without a central server. This flexibility allows them to stay productive, even in remote areas.
  2. Complete History: Users can see the entire project history, including all changes, dates, and times. This detailed record helps track updates and shows how the project has progressed.
  3. Enhanced Collaboration: Many users can simultaneously work on different project sections. Once they're done, they can merge their changes, which helps minimize conflicts.
  4. Improved Backup: Since everyone has a full copy of the project, the chance of losing data is low. If the central server goes down, users can still access their copies.



Alright, guys. Now, I'm pretty sure you understand the official Git definition: "Git is a free and open-source distributed version control system".

Conclusion:

Git is a powerful tool that changes how developers manage their projects. As a distributed version control system, Git allows users to work independently or collaboratively while tracking file changes. Whether handling a small project or collaborating with a large team, Git provides the flexibility and security you need to manage your code successfully. Learning and using Git can help you work better and make your projects more successful.

Follow my Medium profile here for more insights and updates!



To take your JavaScript skills to the next level, consider diving deeper with comprehensive Udemy courses on Node.js,   React, and the MERN Stack. These courses will provide hands-on projects, teach advanced techniques, and help you effectively leverage closures to build sophisticated and dynamic web applications. Start learning today and empower yourself to become a skilled full-stack developer!

Top comments (0)