Understanding Git and GitHub Terms
With a language all its own, this quick guide to common terms of GitHub and Git will have you collaborating in no time.Repository
A repository is the most basic element of Git and GitHub. Imagine it as a project’s folder. A repository contains all of the project files (including documentation), and stores each file’s revision history.Repositories can be public (visible to everyone) or private (visible only to you and people you explicitly share access with).
Commit
An individual change to a file (or set of files). With Git, every time you save it creates a unique ID (a.k.a. the “SHA” or “hash”) that allows you to keep record of what changes were made when and by who. Commits usually contain a commit message which is a brief description of the changes made. Key characteristics of commits:- Each commit has a unique identifier (SHA hash)
- Commits are immutable once created
- Commits form a directed acyclic graph (DAG) representing your project history
- Good commit messages help your team understand the evolution of the codebase
Branch
A parallel version of a repository. It is contained within the repository, but does not affect the main branch, allowing you to work freely without disrupting the “live” version.Branches in Git are lightweight and cheap to create. This makes Git’s branching model one of its most powerful features.
Remote
The connection of a local repository with one on GitHub. It permits revision history to be synchronized by publishing local commits and downloading any new changes from GitHub. Common remote names:origin- The default name for your primary remote repositoryupstream- Often used for the original repository when you’ve forked a project
Pull Request
A feature on GitHub which provides conversation, line-by-line code review, change history analysis, and summaries of modified files.Pull requests are a GitHub feature, not a Git feature. They enable collaboration and code review before merging changes into the main branch.
Configuring Git
The first thing to setup when using Git is two important fields about the user. This allows appropriate credit and traceability for project contributions.Additional Useful Configuration
Versioning Files
Versioning files begins by creating a repository on your GitHub account. File authoring and editing can be performed through the web interface or by acquiring the repository locally from the command line.Cloning a Repository
clone command:
- Downloads the entire repository history
- Creates a new directory with the project name
- Automatically sets up the
originremote - Checks out the default branch
Making Changes with Branches
Repository contributions are commonly made through branches and commits focused on small pieces of work.You can combine branch creation and switching with:
git switch -c [name]Completing the Work
When the feature work reaches completion, the branch can be merged locally or pushed to GitHub for code review.Checking Status and Changes
As commits can be efficiently made, the state of any new, modified, or missing files can be verified and quickly validated.Integrating Changes
Commits can be made against any branch and in any order. Commonly, this is performed against the main branch as means of feature or bug-fix integration.Merges result in all commit history becoming traversable, and eliminating the need for the branch label to remain. The
-d flag safely deletes branches that have been fully merged.Sharing and Retrieving Changes
Setting Up a Remote
Sharing commit history requires only a destination repository, one on GitHub, and a single setup step.origin remote is the traditional name for the primary remote repository, but you can use any name you prefer.
Pushing Changes
With a remote setup, and the traditional name of “origin” aliased to the URL, publishing local commits is simple.Pulling Changes
Retrieving changes from a shared repository and automatically merging in any new commits locally is performed in a multi-step operation run by one command.git pull does:
- Fetches changes from the remote repository (
git fetch) - Merges those changes into your current branch (
git merge)
You can also use
git fetch followed by git merge separately if you want to review changes before merging them.Common Workflows
Feature Branch Workflow
- Create a new branch for your feature
- Make changes and commit them
- Push the branch to GitHub
- Open a pull request
- Review and merge the pull request
- Delete the feature branch
Keeping Your Branch Up to Date
Best Practices
Writing Good Commit Messages
Good commit messages help your team understand the evolution of the codebase:- Use the imperative mood (“Add feature” not “Added feature”)
- Keep the first line under 50 characters
- Provide additional context in the body if needed
- Reference issue numbers when applicable