DEV Community

Cover image for Let's Talk Version Control
Shavon Harris
Shavon Harris

Posted on

Let's Talk Version Control

Understanding Git can be really confusing. I have been using Git for quite some time, but I sometimes found it difficult to explain. This guide aims to equip you with the essential language and concepts of version control so that you do not have that problem.

What is Git?

Imagine you're writing a novel collaboratively. Each contributor makes changes—maybe deleting a comma or adding a whole new chapter. Git is like an attentive editor who keeps track of all these changes. Not only does it help you see what others are doing but it also helps you integrate these changes smoothly to create a final, cohesive manuscript.

Git is the most popular tool for version control, but it's not the only option. Alternatives like Mercurial or Subversion also offer ways to manage project versions:

  • Subversion (SVN) is like a traditional library where a single, central ledger records every change in the books.
  • Mercurial, like Git, is something like each writer maintaining their own detailed notebook of changes.

So, as a developer, I would use Git or Mercurial so that myself and my colleagues can access an identical version of the project.

Understanding Different Types of Version Control

Version control systems can be classified into three main types:

  1. Local Version Control: This is like keeping a personal diary of changes on your own computer.

  2. Centralized Version Control (CVC): Imagine a club where all decisions are recorded in a single register kept at the club's headquarters.

  3. Distributed Version Control (DVC): (This is the most popular version) Each member of the group keeps their own copy of the decision record, allowing operations even when away from the club. Distributed allows for the greatest amount of control and flexibility.

Most people choose Git because it is fast, flexible, and supported by major platforms like GitHub, GitLab, and Bitbucket, which enhance community support.

The Three States of Git Files

Understanding the file states in Git is crucial:

  1. Modified: Your file has changes that are not yet committed to your database. It's like marking up a draft without finalizing the changes.

  2. Staged: You're ready to commit the changes. Think of it as wrapping a gift before giving it.

  3. Committed: The changes are safely stored in your local database, something like storing the wrapped gift in a safe until the party.

After committing, you push your changes to a remote repository.

Key Concepts and Operations

  • Remote Repository: A remote repo is like a shared library on the internet or a network where everyone can access the books at the SAME TIME.
  • Common Operations:
    • Creating and Switching Branches: Developers are encouraged to utilize branches such as dev, test, and prod. This structure allows you to switch between different stages of development. The primary advantage is the ability to thoroughly test changes in the test branch before merging them into the prod (production) branch. This strategy helps prevent the introduction of breaking changes to your main deployment.
    • Pulling changes: Bringing the latest updates from the shared library to your personal collection.
    • Pushing changes: Sending your latest writings to the shared library for others to access.

Best Practices

  • Commit Early and Often: Regular updates help colleagues stay in sync, provide feedback, and avoid complex merging.
  • Understanding Merging and Rebasing: Merging integrates changes from one branch to another to create a unified history. Rebasing is like rearranging the books on your shelf to make it look as if they've always been in that order.

Conclusion

By now, you should have a clearer understanding of how Git functions as a version control system—a digital history for every change, ensuring that collaborations go smoothly and efficiently.

Happy coding!

Extra resources

Top comments (0)