Intro to Git – Version Control Systems – Centralized Version Control Systems



Intro to Git – Version Control Systems – Centralized Version Control Systems

0 0


jonasatwork.github.io

Overview of git

On Github JonasAtWork / jonasatwork.github.io

Intro to Git

jonasatwork.github.io

Agenda

Version Control Systems

Team Foundation Version Control

Git

Using Git

Using Git with GitHub

Git Workflows

Git Resources

Version Control Systems

Key points for all Version Control System...

Define a Project

  • define what objects make up that project
  • define who has access to that project

Keep track of historical changes within a project

Make structural changes to the project

  • add objects
  • remove objects
  • create alternate versions of objects (branching)
  • combine alternate object versions into one object (merging)

Centralized Version Control Systems

(CVCS)

  • TFVC (Team Foundation Version Control)
  • CVS (Concurrent Versions System)
  • SVN (Subversion)
  • VSS (Visual Source Safe)

All of the work to keep track of files in a CVCS is ONLY done in one central place (i.e. the server)

Whether there are 1, 10, or 1000 developers working on a project, there is only ever one repository in a CVCS

this implies a few important points about a CVCS...

To work on the project files, you need access to the centralized server

we need network access to reach the server

There can only ever be one person editing a file at a time

All actions affecting the structure of the project...

  • must be done on the server using network and server resources (not local resources)
  • immediately affect everyone with access to the server

Decentralized Version Control Systems

(DVCS)

  • Git
  • Hg (Mercurial)
  • Bazaar
  • Fossil

All of the work to keep track of files in a DVCS is CAN be done anywhere the repository exists

A repository can exist on any machine (server, "team box", my machine, your machine ... anywhere)

this implies a few important points about a DVCS...

To work on the project files, you only need access to your local filesystem

You don't need network access to reach your repository

No one else can "lock" a file in your repository. This means...

...any file can be worked on within your own copy of the repository, regardless of who else may be working on that file

All actions affecting the structure of the project...

  • can be done locally on your machine (local == cheap)
  • wont affect anyone else until you explicitly push your changes

A CVCS locks

UNLOCK --> MODIFY --> LOCK

A file is read only when LOCKED, and writable when UNLOCKED

A DVCS merges

MODIFY --> MERGE

Changes to files are MERGED with the file that currently exists in the repository

Team Foundation Version Control

(TFVC)

TFS

TFVC

TFVC != TFS

Why TFVC is worth a look

Enterprise wide license for use of TFS

Deeply integrates with Visual Studios and Windows

TFVC handles big binary files very well

  • All of the prior versions are kept on the server and off of my machine
  • This is a strength of TFVC and just about any other CVCS

Why you should look elsewhere

Not using a Microsoft stack (i.e. Java Developers)

Enterprise scale TFS may be overkill

TFVC is more susceptible to network problems

TFVC can be cumbersome with rapid development

  • frequent branching and merging make this type of development much easier, but this can be more trouble than its worth in TFVC
  • This is a weakness of TFVC and just about any other CVCS

Git is a tool developed for the command line

But Git has robust GUI's too

Why Git is awesome :)

Deep integration with just about everything

Git can be as complex or simple as you need it to be

Works well remotely, without network access if needed

Flexible development workflows

Git encourages frequent branching and merging

  • This is a strength of Git and many other DVCS'

Pitfalls with Git :(

Flexible development workflows do not imply different workflows

A "Distributed Repository" does not mean a "Backed Up Repository"

Git does not handle large numbers of big binary files very well

  • All prior versions of these big files are kept in every repository that is created
  • This is the single biggest drawback to using Git over a CVCS

Using Git

Basic Training

clone

A copy of a repository is called a clone. Cloning a repository copies the entire repository from a remote location and recreates it on your machine

git clone git://github.com/jonasatwork/jonasatwork.github.io.git

Remember, the entire history is passed along every time you clone or synchronize a repository

snapshots

Git does it's work by saving snapshots of repository objects.

view all the snapshots that Git has collected...

git log

staging area

Git is aware of all file additions, deletions, and modifications. You to decide what changes get grouped together into a commit

add changed files to the staging area to group them. Think of this as a future snapshot that you want Git to keep track of

git add index.html css/main.css

commit

A commit creates a new snapshot consisting of the items in the staging area, and appends that snapshot to the end of the current branch

Pro Tip: Adding descriptive commit messages as you go is a great way to provide automated changelog documentation

git commit -m "adjusting element width and color on the main page"

branch

A branch is one particular line in the tree of snapshots. We checkout a branch to make it active

When a branch is active all changes made to files are compared to the most recent snapshot in that branch

git checkout -b awesomeNewFeature

merge

A merge tells Git to integrate all changes made in one branch to another branch

First, we need to move to the branch we want to merge changes into, then we the merge the branch containing all of our changes

git checkout master
git merge awesomeNewFeature
                                

pull

Synchronizing your cloned repository with the remote repository, requires pulling in the most recent changes

git pull origin

push

pushing your changes back to the remote repository depends on your workflow and how the remote is setup

  • push your local changes to the remote repository you are allowed access to

    git push origin master
  • Or submit your changes to the repository owner as a patch so that they may implement your changes (GitHub simplifies this step into a pull request, more on this later...)

github.com github.disney.com

A Git repository in the cloud

  • Work Item and Bug Tracking
  • Code Analytics
  • Social Coding
  • Integrates everywhere Git does
  • Convenient GUI's for the WEB and your machine

User Security for Git

Keeps track of all of your repositories

clone new repositories to your GitHub account. GitHub calls this forking

private repositories allows you to set which users can clone, pull, push, merge or even see the repository

Pull Requests

Request for another developer to pull a branch from your repository into their repository

A Pull Request needs 4 pieces of information:

(GitHub handles much of this with a single button press)

Ultimately the owner of the destination repository decides whether or not to pull in your changes

Collaboration

A discussion thread for every pull request

A wiki for every repository

An issue tracker for every project

Code analytics for every user

Git Workflows

"Git is a workflow construction kit"

-Linus Torvalds

(creator of Git)

Centralized Workflow

Everyone works from one branch in central repository (usually called the master branch)

All changes in user's local repositories are pushed to the master branch

Feature Branch Workflow

The master branch exists as the "production" version of code in the central repository

All changes in user's local repositories are initially pushed as separate branches to the central repository

These feature branches can be reviewed before merging them into the master branch

Git Flow Workflow

Git flow defines several branches representing different stages of your development process

All new development is done as a feature branch off of the Development branch

Git Resources

jonasatwork.github.io

Tutorials and References for Git

GitHub Resources