using git

35
keskiviikkona 28. syyskuuta 2011

Upload: abayomi-ayoola

Post on 15-May-2015

1.090 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: Using Git

keskiviikkona 28. syyskuuta 2011

Page 2: Using Git

Using GitBasics and workflows

keskiviikkona 28. syyskuuta 2011

Page 3: Using Git

Git in a nutshell• Distributed revision control system with an emphasis on speed

• Git does not use a centralized server (like CVS, Subversion)

• Developed by Linus Torvalds on 2005 for maintenance of Linux kernel development

• “I name all my projects after myself. First Linux, now Git.”('git' is British slang for stupid, childish person)

• “Take CVS as an example of what NOT to do”

• Goals

• Very high performance

• Simple design (“Git is a stupid content tracker” as Linus says)

• Strong support for non-linear development (branches)

• Fully distributed workflow

• Able to handle large projects (like Linux kernel)

keskiviikkona 28. syyskuuta 2011

Page 4: Using Git

Version Control SystemsA brief history

keskiviikkona 28. syyskuuta 2011

Page 5: Using Git

Local VCS• First generation of Version Control Systems

• Local database to handle versions

• No collaboration between developers

keskiviikkona 28. syyskuuta 2011

Page 6: Using Git

Centralized VCS• Single server contains all the versioned files

• CVS, Subversion

• Advantages

• Everyone knows everyone else progress

• Easier to administer

• Downsides

• Single point of failure

keskiviikkona 28. syyskuuta 2011

Page 7: Using Git

Distributed VCS• Clients fully mirror the repository

• All revision data lies in .git directories

• Git, Mercurial, Bazaar

• Advantages

• Every checkout is really a full backup of all the data

• Parallel workflows within the same project

• Downsides

• Not (yet!) ;-)

keskiviikkona 28. syyskuuta 2011

Page 8: Using Git

Using GitConcept

keskiviikkona 28. syyskuuta 2011

Page 9: Using Git

Git vs. any other CVS• Other systems store data as changes to a base version of each file

• Git stores data as snapshots of the project over time

keskiviikkona 28. syyskuuta 2011

Page 10: Using Git

Git vs. Centralized CVS

• Most operations are local

• Incredible speed while doing operations

• You can continue your work while been offline (commit data, rollback, etc)

keskiviikkona 28. syyskuuta 2011

Page 11: Using Git

The Three States• Files are always committed, staged or modified

• Can be very useful in large projects

• The whole staging phase can be skipped entirely

keskiviikkona 28. syyskuuta 2011

Page 12: Using Git

Tracked and untracked files• Each file in working copy directory (your project folder) can

be tracked or untracked

• Tracked files can be committed (unmodified), modified or staged

• Untracked files are everything else in your working copy directory

• E.g. in Drupal project sites/default/settings.php would be untracked

• Untracked files can be defined in .gitignore file

keskiviikkona 28. syyskuuta 2011

Page 13: Using Git

Using GitBasic commands

keskiviikkona 28. syyskuuta 2011

Page 14: Using Git

Basic commands

Create clean git project directory

$ git init

In most cases (like Drupal based) clone an existing repository

$ git clone git://git.drupal.org/project/drupal.git myfolder

keskiviikkona 28. syyskuuta 2011

Page 15: Using Git

Basic commandsSee git config

$ git config --list

$ git config --global user.name "Lari Vaartio"

$ git config --global user.email "[email protected]"

Check status of your project

$ git status

Check log info

$ git log

Check local branches and all branches (remote and local)

$ git branch OR $ git branch -r

keskiviikkona 28. syyskuuta 2011

Page 16: Using Git

Creating branchLet’s create our own branch

First select release (tag) you are going to use

$ git tag

$ git checkout DRUPAL-7-0

Check log and branch info

$ git log

$ git branch

Create new branch

$ git checkout -b mearra

keskiviikkona 28. syyskuuta 2011

Page 17: Using Git

Adding filesLet’s add some custom code

$ drush dl addthis

$ git status

$ git add .

$ git commit -m ‘added addthis module’

$ git log

Let’s make some modifications

$ pico sites/all/modules/addthis/README.txt

$ git add sites/all/modules/addthis/README.txt

OR to skip staging entirely

$ git commit -a -m ‘Contact information updated’

keskiviikkona 28. syyskuuta 2011

Page 18: Using Git

Discarding changesTo discard changes which are staged but not committed yet

$ git reset HEAD sites/all/modules/addthis/README.txt

To discard changes which are modified but not staged

$ git checkout sites/all/modules/addthis/README.txt

To rollback previous commit grab a commit from git log

$ git reset 521fa42e (goes to the commit but keeps files)

OR

$ git reset --hard 521fa42e (delete files too)

keskiviikkona 28. syyskuuta 2011

Page 19: Using Git

Ignoring filesLet’s add a file which should be untracked

$ cp sites/default/default.settings.php sites/default/settings.php

$ git status

$ echo "sites/default/settings.php" >> .gitignore

$ git status

$ git add .gitignore

$ git commit -m 'gitignore file added'

keskiviikkona 28. syyskuuta 2011

Page 20: Using Git

Remote RepositoriesShow remote repositories

$ git remote

Add a new one for the project

$ git remote add mearrarepo [email protected]:vaartio/mearrarepo.git

$ git push <repositoryname> <branchname>

Commit new data to remote repository

$ git push mearrarepo mearra

Pull data from remote repository

$ git fetch mearrarepo mearra

$ git pull mearrarepo mearra (fetch and merge)

keskiviikkona 28. syyskuuta 2011

Page 21: Using Git

Merging

Merge new Drupal core version with mearra branch

$ git merge CVS

$ git log

keskiviikkona 28. syyskuuta 2011

Page 22: Using Git

Using GitBranching

keskiviikkona 28. syyskuuta 2011

Page 23: Using Git

Branching

• Branch is a snapshot

Snapshots Commits

keskiviikkona 28. syyskuuta 2011

Page 24: Using Git

Branching

$ git branch testing

Creates a new pointer at the same commit you’re currently on.

keskiviikkona 28. syyskuuta 2011

Page 25: Using Git

Branching

$ git checkout testing

This moves HEAD to point to the testing branch.

keskiviikkona 28. syyskuuta 2011

Page 26: Using Git

BranchingMake a change and commit it.

$ vim test.rb

$ git commit -a -m 'made a change'

keskiviikkona 28. syyskuuta 2011

Page 27: Using Git

BranchingLet’s switch back to the master branch.

$ git checkout master

This moves HEAD to master branch and reverts the files in your working directory back to the snapshot that master points to.

keskiviikkona 28. syyskuuta 2011

Page 28: Using Git

BranchingLet’s make changes to the master branch.

$ vim test.rb

$ git commit -a -m 'made other changes'

keskiviikkona 28. syyskuuta 2011

Page 29: Using Git

Merging branchesLet’s merge iss53 branch to the master.

$ git merge iss53

Step 1 Step 2

Step 3

keskiviikkona 28. syyskuuta 2011

Page 30: Using Git

Using GitDifferent workflows

keskiviikkona 28. syyskuuta 2011

Page 31: Using Git

Centralized Workflow

No differs from CVS or Subversion

keskiviikkona 28. syyskuuta 2011

Page 32: Using Git

Integration Manager Workflow1. The project maintainer pushes to their public repository.

2. A contributor clones that repository and makes changes.

3. The contributor pushes to their own public copy.

4. The contributor sends the maintainer an e-mail asking them to pull changes.

5. The maintainer adds the contributor’s repo as a remote and merges locally.

6. The maintainer pushes merged changes to the main repository.

keskiviikkona 28. syyskuuta 2011

Page 33: Using Git

Dictator and Lieutenants Workflow1. Regular developers work on their topic branch and rebase their work on top of master. The

master branch is that of the dictator.2. Lieutenants merge the developers’ topic branches into their master branch.

3. The dictator merges the lieutenants’ master branches into the dictator’s master branch.

4. The dictator pushes their master to the reference repository so the other developers can rebase on it.

keskiviikkona 28. syyskuuta 2011

Page 34: Using Git

Summary• Git is distributed VCS

• Git stores snapshots not changes

• Nearly all operations are local and therefore they are very fast

• Branch is a snapshot, not files in a separated directory

• Git supports multiple remote repositories which enables different workflows

• Git is powerful

keskiviikkona 28. syyskuuta 2011

Page 35: Using Git

Thanks!

keskiviikkona 28. syyskuuta 2011