D   A   T   A   W   O   K





Creation: December 28 2015
Modified: September 11 2018

GIT REFERENCE

Basics

Note: configuration settings are not propagated from one repository to another during a clone.

Configuration

Configuration file hierarchy:

  1. .git/config : repository specific (--file);
  2. ~/.gitconfig : user specific (--global);
  3. /etc/gitconfig : system wide (--system);

core.filemode - false to ignore permission changes.
core.bare - boolean indicating if the repository has a working directory.
core.autocrlf - converts CRLF into LF when a file is added to the index, and vice versa when code is checked out onto the file system. core.editor - default editor, if not set git tries to use vi.

user.name - name to be used in new commits. user.email - email to be used in new commits.

To check current settings

$ git config --list

Because git reads the same key from different files, some keys may be repeated. The configuration files are parsed in the order reported above. And the last value will be used.

Every git command has it's help page. There are three ways to get the manual page

$ git help <verb>
$ git <verb> --help
$ man git-verb

Object Types

To each object is given an SHA1 identifier computed on it's content.

Plumbing (low-level) commands

Low level commands that are not usually invoked directly.

Snapshotting

The commit command is the concatenation of write-tree and commit-tree.

Porcelain (high-level) commands

Setup

Basic Snapshotting

Inspection

Miscelanea

Common options

Repository setup

Init

Create an empty repository or reinitialize an existing one

git init [directory]

Common options

--bare - Create a bare repository

Clone

Clone a repository into a new directory

git clone <repo> [<dir>]

Creates remote-tracking branches for each branch in the cloned repository, and creates and checks out an initial branch that is forked from the cloned repository's current active branch.

If specified, the repository is cloned into dir.

Common options

--b, --branch <branch> - Checkout <branch> instead of the remote's HEAD

Status

Show the working tree status

git status [<options>]

Displays paths that have differences between the index file and the current HEAD commit, paths that have differences between the working tree and the index file, and paths in the working tree that are not tracked (and are not ignored by gitignore).

Common options

Add

Add file contents to the index

git add [<pathspec>]

Updates the index using the current content found in the working tree, to prepare the content staged fo the next commit.

The "index" holds a snapshot of the content of the working tree, and it is this snapshot that is taken as the contents of the next commit. Thus after making any changes to the working tree, and before running the commit command, you must use the add command to add any new or modified files to the index.

This command can be performed multiple times before a commit. It only adds the content of the specified file(s) at the time the add command is run; if you want subsequent changes included in the next commit, then you must run git add again to add the new content to the index.

Common options

Remote

Manage a set of tracked repositories

git remote

Without options it shows the list of existing remotes (defaults to origin).

Common options

Fetch

Download objects and refs from another repository

git fetch

Once the remote is fetched it can be inspected and eventually merged to the current project. The fetch command only new work that has been pushed to that server since the repository has been cloned (or last fetched).

Remote tracking branches are updated.

Common options

Merge

Join two or more development histories together.

git merge

Incorporates changes from the named commits (since the time their histories diverged from the current branch) into the current branch.

Common options

Pull

Fetch from and integrate with another repository or a local branch

git pull

In it's default mode, the pull command is a shorthand for a fetch followed by a merge FETCH_HEAD.

Common options

Push

Update remote refs along with associated objects

git push

The command works only if you are pushing to a repository where we have write access and if nobody has pushed in the meantime, that is there are remote modifications that we do not have yet. It is also used to push a new branch to the remote repository.

Common options

Tag

Create, list, delete or verify a tag object signed with GPG.

git tag

Tipically a tag is used to mark a release point. Without options the command lists all the available tags in alphabetical order.

There are two main types of tags:

Common options

Revert

Revert some existing commits

git revert <commit>

Undoes a committed snapshot. Instead of removing the commit from the project history, it appends a new commit with the resulting content. This prevents git from loosing history.

davxy