home

Below is documentation on git. The primary reference material is the git book; it is published on the git website, where you can download git.

Definitions

A version control system (vcs) records changes to a set of files; each change constitutes a new version of the file set. git is a vcs. .git is a directory, and it is known as a git repository. .git records changes to the files within the directory it is located, per git's and the user's instructions. git is differentiated from other vcss (e.g. svn), because it directly records files, instead of file deltas.

Basic Use

From the user's perspective, there are three domains: working directory, staging area, and repository. The working directory is the directory that stores the file set and repository. The user creates and alters files here. The staging area is simply that -- where files are staged to be recorded; the user adds altered files from the working directory to the staging area. The repository records the files in a database. The user commits files from the staging area to the repository, thus recording a new version of the file set.

A file set version is known as a commit. The user must write a commit message; conventions can be found here. The repository also stores .git configuration, that can be altered by the user. An example of a typical sequence of user actions: alter a file in the working directory, add the altered file to the staging area, and commit the staged file to the repository. If a remote repository exists (e.g. GitHub), the user may also push (or request the remote repository user to pull) a version of the file set.

Branching

A branch is a pointer to a commit. Each commit points to the prior commit. Therefore, a branch can access each commit preceding the commit to which it is pointing -- it has access to the complete history of the file set. A repository's first commit is pointed to by the default branch, called master.

A repository may have multiple branches. A user may switch branches, which will switch the working directory's file set to the commit pointed to by the specified branch. After such a switch, the user is known as being on the specified branch, and the specified branch is known as the current branch.

The current branch's commit file set may be unified with another branch's commit file set, if there are no common files with conflicting lines of characters; this is a merge. If the merging branch's commit can access the current branch's commit, the merge results in both branches pointing to the merging branch's commit; this merge method is known as "fast-forward". If the current branch and merging branch can both access a previous commit, but the merging branch cannot access the current branch's commit, the merge results in a new commit to which the current branch points; this is known as a merge-commit.

If a user attempts to merge two branches with at least one common file with at least one line of differing characters, the merge will fail. The user must resolve the conflict to perform a successful merge. A typical example of merging, with visualization, can be found here.

Remote

A remote repository is a repository that is not the local repository. A local repository user may have no access, read access, or read-write access to a remote repository. A local repository user may access the remote repository at its address; git compatible address types can be found here. The local repository user typically names a remote repository by associating the specified name with the remote repository address.

If a local repository user has read access or read-write access, they may download remote repository data; this is a fetch. The local repository user may merge the current branch with a branch from the downloaded remote repository. A fetch then merge is a pull. The local repository user may also copy a branch from the downloaded remote repository. A local repository user may copy an entire remote repository; this is a clone -- the local repository's default name for the cloned remote repository is origin. A local repository user may name and fetch from multiple remote repositories. If a local repository user has read-write access, they may merge a remote repository's branch with the current branch; this is a push.

GitHub

GitHub offers repositories. The creator of a GitHub repository is known as the owner; they set access constraints. They also set the instructions for interacting with the repository, typically using topic branches.

An example: a read-write access user of the repository creates a new branch from master relating to a topic. A topic may be a feature, issue, etc. A read access user copies the repository in GitHub; this is a fork. The read access user clones the fork. The read access user completes the typical sequence of actions written in the Basic Use section above. The read access user pulls the repository topic branch and resolves conflicts. The read access user pushes the topic branch to the fork topic branch. The read access user requests the read-write access user pull the fork topic branch. The read-write access user pulls the fork topic branch. The read-write access user pulls the master branch and resolves conflicts. The read-write access user pushes the topic branch to the master branch. More discussion can be found here.

Configuration

The user typically configures a username, email, and line endings.

Commands

Below are the git commands associated with the actions written above. A manual page includes definitions, options, and examples; a git command's manual page can be accessed by appending --help to the command.

Create repository

git init

Add files to staging area

git add

Commit staged files to repository

git commit

Create branch

git branch

Switch branches

git switch

Merge branches

git merge

Name remote repository

git remote

Fetch remote repository

git fetch

Clone remote repository

git clone

Pull remote repository

git pull

Push to remote repository

git push

Configure git

git config