Git

Repository Contents

  • The purpose of Git is to manage a project. Git stores this information in a data structure called a repository.
  • A git repository contains
    • A set of commit objects.
    • A set of references to commit objects, the heads.
  • The Git repository is stored in the same directory as the project itself, in a subdirectory called .git.

Commit Objects

A commit object contains three things:

  • A set of files, reflecting the state of a project at a given point in time.
  • References to parent commit objects.
  • A unique name.

Heads

  • A head is simply a reference to a commit object. Each head has a name.
  • By default, there is a head in every repository called master.

A Simple Repository

Commands

Git Config

Set up your name and email address for Git to use to sign your commits.

$ git config --global user.name "Scott Chacon"
$ git config --global user.email "schacon@gmail.com"

This wil set up file ~/.gitconfig

Initializing a new git repo

git init

Cloning a Repository

To clone a repository

git clone git://git.kernel.org/pub/scm/git/git.git

Making Changes

To add some files use:

git add file1 file2 file3

Use diff to see what is about to be committed:

git diff --cached

To get a summary:

git status

Commit changes:

git commit

Alternatively, instead of running git add beforehand, you can use

$ git commit -a

Commit messages are not required but it's a good idea to summarize your change.

Basic Branching and Merging

A single git repository can maintain multiple branches of development. To create a new branch named "experimental", use

git branch experimental

If you run

git branch

you will get a list of all existing branches.

To merge the changes made in experimental into master, run

git merge experimental

To delete the experimental branch

git branch -d experimental

This command ensures that the changes in the experimental branch are already in the current branch.

To force a deletion use

git branch -D experimental
page_revision: 1, last_edited: 1256745932|%e %b %Y, %H:%M %Z (%O ago)
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-Share Alike 2.5 License.