Chapter 1. Introduction
In this chapter Iâll start by introducing Git and GitHub. What are they, what is the difference between them, and why would you want to use them? Iâll then introduce some other common terms that youâll often hear mentioned when people are discussing GitHub. That way youâll be able to understand and participate in discussions about your projects more easily.
What Is Git?
Git is a version control system. A version control system is a piece of software designed to keep track of the changes made to files over time. More specifically, Git is a distributed version control system, which means that everyone working with a project in Git has a copy of the full history of the project, not just the current state of the files.
What Is GitHub?
GitHub is a platform where you can upload a copy of your Git repository (often shortened to repo), hosted either on GitHub.com, by your company on a cloud provider (like Azure, AWS, or IBM Bluemix), or on your companyâs own servers behind its firewall. But more than just uploading your Git repositories, it allows you to collaborate much more easily with other people on your projects. It does that by providing a centralized location to share the repository, a web-based interface to view it, and features like forking, Pull Requests, Issues, Projects, and GitHub Wikis that allow you to specify, discuss, and review changes with your team more effectively.
Why Use Git?
Even if youâre working on your own, if you are editing text files, there are a number of benefits to using Git, including the following:
- The ability to undo changes
- If you make a mistake, you can go back to a previous point in time to recover an earlier version of your work.
- A complete history of all the changes
- If you ever want to see what your project looked like a day, week, month, or year ago, you can check out a previous version of the project to see exactly what the state of the files was back then.
- Documentation of why changes were made
- Often itâs hard to remember why a change was made. With commit messages in Git, itâs easy to document for future reference why youâre making a change.
- The confidence to change anything
- Because itâs easy to recover a previous version of your project, you can have the confidence to make any changes you want. If they donât work out, you can always get back to an earlier version of your work.
- Multiple streams of history
- You can create different branches of history to experiment with different changes to your content or to build out different features independently. You can then merge those back into the main project history (
master
branch) once theyâre done, or delete them if they end up not working out.
Working on a team, you get an even wider range of benefits when using Git to keep track of your changes. Some of the key benefits of Git when working with a team are:
- The ability to resolve conflicts
- With Git, multiple people can work on the same file at the same time. Usually Git will be able to merge the changes automatically. If it canât, Git will show you what the conflicts are and you will hopefully be able to easily resolve them.
- Independent streams of history
- Different people working on the project can work on different branches, allowing them to work on separate features independently and then merge the features when theyâre done.
Why Use GitHub?
GitHub is much more than just a place to store your Git repositories. It provides a number of additional benefits, including the ability to do the following:
- Document requirements
- Using issues, you can either document bugs or specify new features that youâd like to have your team develop.
- Collaborate on independent streams of history
- Using branches and pull requests, you can collaborate on different branches or features.
- Review work in progress
- By looking at the list of pull requests, you can see all of the different features that are currently being worked on; by clicking any given pull request you can see the latest changes and all of the discussions about the changes, check the status of an integration like a Continuous Integration (CI) server, or even add your own review to approve changes before they are accepted.
- See team progress
- Skimming the pulse or looking through the commit history allows you to see what the team has been working on.
Key Concepts
There are a number of key concepts that youâll need to understand to work effectively with Git and GitHub. Here is a list of some of the most common terms, with a short description of each and an example of how they might be used in conversation:
- Commit
- Whenever you save your changes in one or more files, you can create a new commit in Git. A commit is like a snapshot of your entire repository at that point in time, not just of one or two files. So naturally, after you change those files, you will want to update the repository by taking a new snapshot. Example usage: âLetâs commit these changes and push them up to GitHub.â
- Commit message
- Every time you make a commit, you need to supply a message that describes why the change was made. That commit message is invaluable when trying to understand later why a certain change was implemented. Example usage: âMake sure to include Susanâs comment about the new SEC guidelines in the commit message.â
- Branch
- A branch is an independent series of commits off to one side that you can use to try out an experiment or create a new feature. Example usage: âLetâs create a branch to implement the new search functionality.â
master
branch- Whenever you create a new Git project, there is a default branch created called
master
. This is the branch that your work should end up on eventually, once itâs ready to push to production. Example usage: âRemember never to commit directly tomaster
.â - Feature (or topic) branch
- Whenever youâre building a new piece of functionality, youâll create a branch to work on it. That is called a feature branch. Example usage: âWeâve got way too many feature branches. Letâs focus on getting one or two of these finished and into production.â
- Release branch
- If you have a manual QA process or have to support old versions of your software for your customers, you might need a release branch as a place to make any necessary fixes or updates. There is no technical difference between a feature or release branch, but the distinction is useful when talking about a project with your team. Example usage: âWeâve got to fix the security bug on all of our supported release branches.â
- Merge
- A merge is a way to take completed work from one branch and incorporate it into another branch. Most commonly youâll merge a feature branch into the
master
branch. Example usage: âGreat job on the âmy accountâ feature. Could you merge it intomaster
so we can push it to production?â - Tag
- A tag is a reference to a specific historic commit. Tags are most often used to document production releases so you know exactly which versions of the code went into production and when. Example usage: âLetâs tag this release and push it to production.â
- Checkout
- Checking out enables you to go to a different version of the projectâs history and see the files as of that point in time. Most commonly youâll check out a branch to see all of the work that has been done on it, but any commit can be something you check out. Example usage: âCould you check out the last release tag? Thereâs a bug in production that I need you to replicate and fix.â
- Pull request
- Originally, a pull request was used to request that someone else review the work youâd completed on a branch and then merge it into
master
. Now, pull requests are often used earlier in the process to start a discussion about a possible feature. Example usage: âGo create a pull request for the new voting feature so we can see what the rest of the team thinks about it.â - Issue
- GitHub has a feature called Issues that can be used to discuss features, track bugs, or both. Example usage: âYouâre right, the login doesnât work on an iPhone. Could you create an issue on GitHub documenting the steps to replicate the bug?â
- Wiki
- Originally developed by Ward Cunningham, wikis are a lightweight way of creating web pages with simple links between them. GitHub projects often use wikis for documentation. Example usage: âCould you add a page to the wiki to explain how to configure the project to run on multiple servers?â
- Clone
- Often youâll want to download a copy of a project from GitHub so you can work on it locally. The process of copying the repository to your computer is called cloning. Example usage: âCould you clone the repo, fix the bug, and then push the fix back up to GitHub later tonight?â
- Fork
- Sometimes you donât have the necessary permission to make changes directly to a project. Perhaps itâs an open source project written by people you donât know, or a project written by another group at your company that you donât work with much. If you want to submit changes to such a project, first you need to make a copy of the project under your user account on GitHub. That process is called forking the repository. You can then clone it, make changes, and submit them back to the original project using a pull request. Example usage: âIâd love to see how youâd rewrite the home page marketing copy. Fork the repo and submit a pull request with your proposed changes.â
Donât worry if all the terminology seems overwhelming at first. Once you start working with some real projects, itâll all make a lot more sense! In the next chapter weâll look at the various elements of a GitHub project and how you can use them to get a sense of progress on a project.
Get Introducing GitHub, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.