How Git and GitHub Work Together
Explore how Git and GitHub work together to support source control and collaboration. Understand key concepts like repositories, commits, pushing, and cloning, and see how teams can coordinate code changes across locations. This lesson builds your foundation in managing code with best practices using Git and GitHub.
We'll cover the following...
Introduction
Not long ago, organizations were not worried about whether or not source (version) control existed. This was, however, until organizations realized code was walking out the front door, software deployments were failing because of bugs that were fixed already, and the lack of history about the code. It was more than normal for code to be kept on a developer’s machine or in a shared drive.
The problem with the “no source control” approach is there isn’t any history of the code, no tests being run, and no innovation between teams. Source control opens up the locked door of code being in a location that no one knows about and allows everyone to share ideas while delivering quality.
Source control also has the ability to help collaboration between teams while writing code. Anyone on the team, in any country, at any time of the day can work on code together. The participants collaborating don’t even have to be on the same team. There could be a QA engineer, DevOps engineer, and cloud engineer all working on the same codebase together.
In this chapter, you will dive deep into how Git and GitHub helps make source control and collaboration possible. By the end of this chapter, you will have a clear understanding of what it means to not only practice source control best practices, but also understand the ins and outs of Git and GitHub for storing development and deployable production code.
Git is a modern distributed version control system (DVCS) created in 2005 by Linus Torvalds. DVCS provides developers the ability to have a copy of the code from their
When using Git, changes are staged and then committed to a repo. When a file is committed to a repo, it becomes part of the repo making it possible to perform rollbacks to previous versions.
GitHub is a free source control system that is based on DVCS and allows you to save code in public and private repositories. GitHub is used around the world by many developers and operations individuals alike. You can follow people to see what they work on and work together on the same GitHub project if you find their work interesting. Cooperative projects like these are great resume builders. In fact, the authors are using GitHub to store the code for this course!
How Git and GitHub work together
Many who are new to the world of Git and GitHub typically ask: “What’s the difference between the two?” It’s very common to see Git and GitHub interchanged in the community. However, these two platforms couldn’t be more different.
Git, as you learned earlier, is a source control product that allows you to work with code in a repository with other people. While this is, of course, important, Git cannot just work by itself. Git is the platform behind the scenes and at the command-line. There needs to be a platform that has a UI, stores the code, has a portal for users to log into, and interaction capabilities with the code. This is where GitHub comes into play.
GitHub uses Git behind the scenes as the version control system. GitHub is the web-based UI that hosts repositories for Git.
A team needs a centralized location to store code to ensure everyone not only knows what or why the code has changed but to keep a history of changes. In many organizations, developers, QA, and even operations nowadays write code. There’s a strong chance that even the simplest of codebases have multiple people working on it at once.
Collaborators on a coding project come and go. When an organization implements a source control system like GitHub, it not only helps the team currently working on the code but also any new collaborators that come after.
One of the biggest benefits of working with a DVCS system like GitHub is the ability to work with others. If you have an internet connection, you can collaborate with people around the world. Location doesn’t matter. Teams can be spread across states, time zones, and countries and can all be working on the same code together in real-time.
When collaborating on code, everyone needs to not only read code but also change and add code as required too. Using Git and GitHub, you can perform actions like commit, push, and clone code to encourage collaboration.
-
Committing code is creating a new file or making a revision to an existing file. You make a change and tell the system about the change.
-
Pushing code sends files to a GitHub repository that is part of a local Git repository. The code still exists locally, but it’ll be saved to the repository, so others can see it and clone it.
-
Cloning code copies a GitHub repo to a local Git repo. The code still stays in the GitHub repo, but you now have a copy to modify and work with.