Skip to content

Instantly share code, notes, and snippets.

@smiller171
Last active May 29, 2019 15:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save smiller171/a4eeec96f53ffb392082f3f0921e26f1 to your computer and use it in GitHub Desktop.
Save smiller171/a4eeec96f53ffb392082f3f0921e26f1 to your computer and use it in GitHub Desktop.
Git In Depth

Git In Depth

Concepts

Version Control System (VCS)

A VCS is software that helps developers work together and mainain a complete history of their work.

git

git is an open source distributed VCS optimized for speed and cheap branching.

GitHub

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.

repository

A repository is where all of your version history is stored.

remote repository

When working with git you will usually have one or more remote repositories (such as a GitHub repository).

local 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.

clone

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.

working directory

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.

commit

A commit holds the state of the repository at a point in time.

staging area

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.

branch

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.

checkout

Apply the current state of a branch to your working directory.

HEAD

A pointer to the latest commit in a branch

merge

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 branch typo-fix with a change that fixes a typo on the home page, you would merge typo-fix into master before re-deploying the code in master to production.

tag

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.

push

You push code from your local repository to a remote repository to sync your local changes with the remote.

fetch

Fetching downloads metadata about any changes in the remote repository, but does not apply those changes to your working directory or local repository.

pull

Pulling merges any changes in the remote repository to your local repository and updates your working directory (must fetch first).

conflict

A conflict occurs when different changes are made to the same line in a file. For example:

  • Branch develop has a file index.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.

pull request

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.

common commands

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment