Distributed Version Control

Steven J Zeil

Last modified: Nov 20, 2013

Contents:
1. git
1.1 History
1.2 Exploration
2. Collaboration
3. Eclipse Integration

Distributed version controls models relax the dependency upon a central repository as the keeper of the one true project.


Sounds Like Anarchy


A Synthesis of Local and Remote

In a distributed model, a developer maintains


Two-Level Commits

The local/remote division helps resolve a common dilemma in centralized VC systems:

A newly checked-out copy should always compile and yield a (roughly) working product.

a.k.a., “Don’t break the build!”

1. git

git Revisions


git Revisions

A git repository contains, conceptually, a collection of snapshots (a.k.a., commit objects, a.k.a. revisions, a.k.a. versions).

Each snapshot contains


Heads

A git repository also contains a collection of heads.

These are human-assigned names for selected snapshots.


How shall I name thee?

Snapshots in a repository may be identified by giving

1.1 History


Common Local History Commands

1.2 Exploration

Every Local Repository is a Branch

So one way to “branch” in git is to simply check out a new copy.

But sometimes we want to branch within a local repository


Branching Within a Local Repository


When Should I Commit? (Another perspective)

git users consider branches to be cheap.

So some advocate


Merging Local Branches

2. Collaboration

Collaboration in git takes the form of interaction between your local repository and a remote repository.


Starting from a Remote Repository

If you are working with an existing remote repository

git clone remoteSpec

creates a new local repository as a copy of the remote one.


Cloning

Suppose that we have a remote repository with two branches and a few commit objects on each.

git branch --track enhanced origin/enhanced


Life after Cloning

Suppose each repository adds a commit along the trunk:

local
Our local heads separate from the remembered positions of the remote ones.

Fetching Remote Changes

The basic command to get changes from the remote repository is git~fetch %\saveAndMeasurePic[0.55\linewidth]{gitFetched}

Remember, each repository is, in essence, a new (set of) branch(es)


Pulling Remote Changes

More commonly used than fetching is pulling, which combines a fetch and a merge
git pull origin master


Pushing to the Remote Repository

The push command

If the remote repository looks like this
and our local repository looks like this
git push origin master


Push is NOT the Opposite of Pull

It’s actually the opposite of fetch

This leads to an important restriction


The remote head must point, before a push, to an ancestor of the commit that it would point to after the push.


This Push Will Fail

If the remote repository looks like this
and our local repository looks like this,

because if it went through, we would lose access to a state already committed in the remote repository.


Avoiding Bad Pushes


Rebasing

Rebasing changes the parent relationship of the current head so that it appears to have been derived directly from some other selected head.

If we start with this and do
git rebase master

we get this.

The Perils of Rebasing

For all the talk about rebasing in the git literature, you would think it was a very common operation.

But,


Why Rebase?

Generally recommended only for

3. Eclipse Integration


Eclipse Integration

Again, a plugin (Egit) is needed. Egit has recently been incorporated into the Eclipse main update/plugin distribution site.

Operations is similar to the CVS and SVN plugins, except that


Eclipse, git, and a Forge

New projects:

  1. A Forge environment will create an empty repository

  2. Use the Git Repository Exploring perspective to clone the repository.
  3. Create a directory to hold the project as a sibling of the .git directory you have just obtained.
  4. In Eclipse, do File Import and select Git. Follow the instructions to name your local repository that you just cloned and “Use New Project Wizard”.

  5. When the regular project wizard starts, direct it to your project folder you created in step 3.

  6. After the new project wizard is completed, Eclipse still will not show the project as managed by Git.
  7. Use Team Add to index to add files to version control.

  8. Team Commit (or Synchronize).

  9. Team Push.


Existing Projects

  1. A Forge environment will contain instructions/settings on how to access the existing repository

  2. Use the Git Repository Exploring perspective to clone the repository.
  3. In Eclipse, do
  4. After the new project wizard is completed, Eclipse might not show the project as managed by Git.
  5. Use Team Add to index to add files to version control.

  6. Team Commit (or Synchronize).

  7. Team Push.