A Simple Introduction to Git: a distributed version ... · A Simple Introduction to Git: a...

Preview:

Citation preview

ASimpleIntroductiontoGit:adistributedversion-controlsystem

CS5010ProgramDesignParadigmsLesson0.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”.Nothingiseverover-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”takesthedatafromtheserverandputsitbothinyourlocalmini-fsandinyourordinaryfiles.

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

WerecommendGithub Desktop

• ThisisaniceUIforgithub.• Ifyourprefer,youcanusethecommandline,oranyothergit interfaceyoulike.

• PointyourcopyofGithub Desktoptouse“GithubforEnterprise”athttps://github.ccs.neu.edu

• Werecommendthatyousetupyourreposto“alwaysrebase”.(Whenwesetupyourrepos,wewilltrytosetthemuptodothisautomatically)

14

Github Desktopusesasimplifiedgitmodel

• InGithub Desktop,“push”and“pull”arecombinedintoasingleoperationcalled“sync”.Sothereareonlytwosteps(“commit”and“sync”)toworryabout,notthree.

15

sync

commit

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

YourworkflowwithGDsync

edit

commit

edit

commit

edit

commit

sync

Bestpractice:commityourworkwheneveryou’vegottenonepartofyourproblemworking,orbeforetryingsomethingthatmightfail.

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

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

Startingyourworksession• Here’swhatyourGithub Desktopshouldlooklikewhenyou

openitup.Observethatyourreposwillbeinthesectionlabeled“Enterprise”.

18

WhereamI?• Theopenbluecircleindicatesthatyouarelookingatthemost

recentlocalfiles

19

Alwaysstartbysyncing• Thiswilldownloadanychangesthatyouoryourpartnerhave

madeonothermachines

20

Clickonadottoseeacommit• Clickingonthelastdotwillshowyouwhatwasinyourlast

commit• Thedotturnsblue

21

• Inthisview,youcanseethefirst6charactersoftheuniqueidentifier(“theSHA”)forthiscommit

• You’llneeditforyourWorksession Report

ThisshowsyourcommitSHA

22

Nowlet’sworkonourfile• Nowthescreenshowsanuncommittedchange.

23

• Wewriteacommitmessage.Thenwe’llclickon“CommittoMaster”

Next,wecommitourwork

24

• Nowitsays“Nouncommittedchanges”again.• Youcanalsoundothecommitifyouwant.

Here’swhatyou’llseeafteracommit

25

• Clickontheopencircletoseewhatwasinyourcommit,andtorecordthecommitSHA.Here’sthatscreenagain:

BesuretorecordthecommitSHA

26

• Yourworkisnotsavedontheserveruntilyousync.

Besuretosync!!!

27

SubmitaWorkSessionReport• Attheendofyourwork

session,submitaworksessionreportviatheweb.

• TheURLfortheworksessionreportwillappearineachproblemset.

• ThereportwillaskfortheSHAofyourlastcommit.YoucangetthisfromtheGithub Desktop,aswe’veshownyou.

28

Otherwaystousegit andgithub

• Therearelotsofpossiblewaystousegit andgithub.

• Ifyouandyourpartnerknowgit well,andyouwanttodosomethingfancierwithmultiplebranches,merges,andwhatnot,feelfreetodoso.

• Butyoushouldbeabletogetbyjustfinewithjustasinglemasterbranch.

29

WebelieveintheKISSprinciple:“KeepItSimple,Stupid!”

Summary

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

– howgit allowsyouandapartnertoworktogether

30

Recommended