a simple introduction to git: a distributed version ... 0.5... · my-project docs manual.docx...

30
A Simple Introduction to Git: a distributed version-control system CS 5010 Program Design Paradigms “Bootcamp” Lesson 0.5 © Mitchell Wand, 2012-2014 This work is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License. 1

Upload: lamnga

Post on 25-Jan-2019

220 views

Category:

Documents


0 download

TRANSCRIPT

ASimpleIntroductiontoGit:adistributedversion-controlsystem

CS5010ProgramDesignParadigms“Bootcamp”Lesson0.5

©MitchellWand,2012-2014ThisworkislicensedunderaCreative Commons Attribution-NonCommercial 4.0 International License. 1

LearningObjectives

• Attheendofthislessonyoushouldbeabletoexplain:– howgit createsamini-filesystem inyourdirectory– whatcommit,push,pull,andsyncdo– theelementsofthebasicgit workflow– howgit allowsyoutoworkacrossmultiplecomputers

– howgit allowsyouandapartnertoworktogether

2

Git isadistributed version-controlsystem

• Youkeepyourfilesinarepository onyourlocalmachine.

• Yousynchronizeyourrepositorywitharepositoryonaserver.

• Ifyoumovefromonemachinetoanother,youcanpickupthechangesbysynchronizingwiththeserver.

• Ifyourpartneruploadssomechangestoyourfiles,youcanpickthoseupbysynchronizingwiththeserver.

3

Git isadistributedversion-controlsystem

• Terminology:Ingit-speak,a“version”iscalleda“commit.”

• Git keepstrackofthehistoryofyourcommits,soyoucangobackandlookatearlierversions,orjustgiveuponthecurrentversionandgobacksomeearlierversion.

4

Asimplemodelofgit

• Mostgit documentationgetsintodetailsveryquickly.

• Here’saverysimplemodelofwhat’sgoingoningit.

5

Yourfiles

my-project docs manual.docx

user_docs.docx

srcmain.rkt

module1.rkt

module2.rkt

module3.rkt

Hereareyourfiles, sittinginadirectorycalledmy-

project

6

Yourfilesinyourgit repository

my-project docs manual.docx

user_docs.docx

srcmain.rkt

module1.rkt

module2.rkt

module3.rkt

.git

Whenyouhaveagit repository,youhaveanadditionaldirectorycalled.git,whichpointsatamini-filesystem.

Thisfilesystemkeepsallyourdata,plusthebellsandwhistlesthatgit needstodoitsjob.

Allthissitsonyourlocalmachine.

7

Thegit client

my-project docs manual.docx

user_docs.docx

srcmain.rkt

module1.rkt

module2.rkt

module3.rkt

.git

Thismini-filesystem ishighlyoptimizedandverycomplicated.Don’ttrytoreaditdirectly.

Thejobofthegit client(eitherGithub forWindows,Github forMac,orasuiteofcommand-lineutilities)istomanagethisforyou.

8

Yourworkflow(part1)

• Youedityourlocalfilesdirectly.– Youcanedit,addfiles,deletefiles,etc.,usingwhatevertoolsyoulike.

– Thisdoesn’tchangethemini-filesystem,sonowyourmini-fs isbehind.

9

ACommit

my-project docs manual.docx

user_docs.docx

srcmain.rkt

module1.rkt

module2.rkt

module3.rkt

.git

commit

Whenyoudoa“commit”,yourecordallyourlocalchangesintothemini-fs.

Themini-fs is“append-only”.Nothing iseverover-writtenthere,soeverythingyouevercommitcanberecovered.

10

Synchronizingwiththeserver(1)

my-project docs manual.docx

user_docs.docx

srcmain.rkt

module1.rkt

module2.rkt

module3.rkt

.git push

Attheendofeachworksession,youneedtosaveyourchangesontheserver.Thisiscalleda“push”.

Nowallyourdataisbackedup.• Youcanretrieveit,onyourmachineor

someothermachine.• Wecanretrieveit(that’showwecollect

homework)

yourlocalmachine aserver,somewhereontheinternet,eg.github.com

11

Synchronizingwiththeserver(2)

my-project docs manual.docx

user_docs.docx

srcmain.rkt

module1.rkt

module2.rkt

module3.rkt

.git pull

Toretrieveyourdatafromtheserver,youdoa“pull”.A“pull”takesthedatafromtheserverandputsitboth inyour localmini-fsandinyourordinary files.

Ifyourlocalfilehaschanged,git willmergethechangesifpossible.Ifitcan’tfigureouthowtothemerge,youwillgetanerrormessage.We'lllearnhowtodealwiththeseinthenextlesson.

yourlocalmachine aserver,somewhereontheinternet,eg.github.com

pull

12

Thewholepicture

my-project docs manual.docx

user_docs.docx

srcmain.rkt

module1.rkt

module2.rkt

module3.rkt

.gitpull

yourlocalmachine aserver,somewhereontheinternet,eg.github.ccs.neu.edu

pull

commit

push

13

ThewholepictureusingGHFW

my-project docs manual.docx

user_docs.docx

srcmain.rkt

module1.rkt

module2.rkt

module3.rkt

.git

yourlocalmachine aserver,somewhereontheinternet,eg.github.ccs.neu.edu

sync

commit

InGihub ForWindowsorGithub ForMac,“push”and“pull”arecombined intoasingleoperationcalled“sync”.Sointheseclients,thereareonly twosteps(“commit”and“sync”)toworryabout,notthree.

sync

14

Yourworkflow(2)sync

edit

commit

edit

commit

edit

commit

sync

Bestpractice:commityourworkwheneveryou’vegottenonepartofyourproblemworking, orbeforetryingsomething thatmightfail.

Ifyournewstuffisscrewedup,youcanalways“revert”toyour lastgoodcommit.(Remember:always“revert”,never“rollback”)

15

UsingGithub forWindows/Mac

16

Yourworkflowwithapartner

sync

edit

commit

edit

commit

edit

commit

sync

sync

edit

commit

edit

commit

edit

commit

sync

sync

edit

commit

edit

commit

edit

commit

sync

You You

YourPartner(oryouonanothercomputer)

Yourpartnergetsyourworkfromtheserver

Yougetyourpartner’sworkfromtheserver

server server

17

Thenewgithub desktop

• Inthenextfewslides,we’llgiveyoutheupdatesfor2015.

• Wewon’tbeusinggithub.com.Insteadwewillbeusing“Github forEnterprise”athttps://github.ccs.neu.edu

• TheuserinterfaceforGHFW/GHFMhaschanged.It’snowcalled“Github Desktop”.

• Inthenextfewslides,we’llshowyouhowyourdailyworkflowlookswithnewinterface.

18

Startingyourworksession• Here’swhatyourGithub Desktopshouldlooklikewhenyou

openitup.Observethatyourreposwillbeinthesectionlabeled“Enterprise”.

19

WhereamI?• Theopenbluecircleindicatesthatyouarelookingatthemost

recentlocalfiles

20

Alwaysstartbysyncing• Thiswilldownloadanychangesthatyouoryourpartnerhave

madeonothermachines

21

Clickonadottoseeacommit• Clickingonthelastdotwillshowyouwhatwasinyourlast

commit• Thedotturnsblue

22

• Inthisview,youcanseethefirst6charactersoftheuniqueidentifier(“theSHA”)forthiscommit

• You’llneeditforyourWorksession Report

ThisshowsyourcommitSHA

23

Nowlet’sworkonourfile• Nowthescreenshowsanuncommittedchange.

24

• Wewriteacommitmessage.Thenwe’llclickon“CommittoMaster”

Next,wecommitourwork

25

• Nowitsays“Nouncommittedchanges”again.• Youcanalsoundothecommitifyouwant.

Here’swhatyou’llseeafteracommit

26

• Clickontheopencircletoseewhatwasinyourcommit,andtorecordthecommitSHA.Here’sthatscreenagain:

BesuretorecordthecommitSHA

27

• Yourworkisnotsavedontheserveruntilyousync.

Besuretosync!!!

28

SubmitaWorkSessionReport• Attheendofyourwork

session,submitaworksessionreportviatheweb.

• TheURLfortheworksessionreportwillappearineachproblemset.

• ThereportwillaskfortheSHAofyourlastcommit.YoucangetthisfromtheGithub Desktop,aswe’veshownyou.

29

Summary

• Inthislessonyouhavelearned– thatgit createsamini-filesystem inyourdirectory– whatcommit,push,pull,andsyncdo– theelementsofthebasicgit workflow– howgit allowsyoutoworkacrossmultiplecomputers

– howgit allowsyouandapartnertoworktogether

30