- VCS
- git
- GitHub
- repository
- remote repository
- local repository
- clone
- working directory
- commit
- staging area
- branch
- checkout
- HEAD
- merge
- tag
- push
- fetch
- pull
- conflict
- pull request
A VCS is software that helps developers work together and mainain a complete history of their work.
git is an open source distributed VCS optimized for speed and cheap branching.
GitHub is a cloud-based service for hosting git repositories in the cloud. It also adds extra features that don't exist natively in git.
A repository is where all of your version history is stored.
When working with git you will usually have one or more remote repositories (such as a GitHub repository).
Because git is distributed, by default you will have a complete copy of the repository locally. This is where you do work, and must sync up with the remote repository frequently.
A clone is a copy of a repository. When you want to work on an existing repository for the first time, you must clone the remote repository to create a local repository.
The working directory is the place on your local file system where files are checked out. You can modify files in this directory just like any other files on your computer, but in order to save your changes to your local repository, you must create a commit.
A commit holds the state of the repository at a point in time.
The staging area is used to tell git what changes to commit. This allows you to make many changes in your working directory, but only commit some of them. This is useful if you want to split changes into multiple commits or want to discard some changes.
A branch represents a line of development. Branches allow people to work on different things in the codebase simultaneously and defer any conflicts until they are ready to merge.
Apply the current state of a branch to your working directory.
A pointer to the latest commit in a branch
Merging is the process of integrating the changes from one branch into another. For example if you have a
master
branch which holds the code in production and a branchtypo-fix
with a change that fixes a typo on the home page, you would mergetypo-fix
intomaster
before re-deploying the code inmaster
to production.
A tag attaches a friendly name to a specific commit to add meaning to a specific commit. Frequently tags are used to mark specific versions of code in a repository. Tags are immutable and can't be moved to a different commit once they have been added.
You push code from your local repository to a remote repository to sync your local changes with the remote.
Fetching downloads metadata about any changes in the remote repository, but does not apply those changes to your working directory or local repository.
Pulling merges any changes in the remote repository to your local repository and updates your working directory (must fetch first).
A conflict occurs when different changes are made to the same line in a file. For example:
- Branch
develop
has a fileindex.html
- Joe pulls down
develop
- Taylor pulls down
develop
- Joe changes
<title>Title</title>
to<title>New Title</title>
- Taylor changes
<title>Title</title>
to<title>Awesome Title</title>
- Joe creates a commit and pushes his change
- Taylor creates a commit and attempts to push her change Taylor's push will be rejected because there is a conflict. Taylor must manually select which version of that line to keep and mark the conflict as resolved before she can push. Alternatively she could abandon her commit and reset her local repo to match the remote.
A pull request (PR) is a GitHub feature which allows you to get feedback on the changes in a branch before merging that branch. This is a useful feature for conducting code reviews and doing automated tests before code is merged and deployed.
All of these actions can be done via the GitHub Desktop app if you prefer a GUI interface. VSCode and Atom also have git support integrated.
- add
adds files to staging area
- commit
create a commit from files in staging area
- push
push local commits to remote
- fetch
get remote metadata
- pull
merge remote commits to local
- branch
create new branch from current commit
- checkout
check out