a simple introduction to git: a distributed version ... · a simple introduction to git: a...

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

Upload: vuongdang

Post on 25-May-2018

253 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: A Simple Introduction to Git: a distributed version ... · A Simple Introduction to Git: a distributed version-control system ... – how git creates a mini-filesystem in ... –

ASimpleIntroductiontoGit:adistributedversion-controlsystem

CS5010ProgramDesignParadigmsLesson0.5

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

Page 2: A Simple Introduction to Git: a distributed version ... · A Simple Introduction to Git: a distributed version-control system ... – how git creates a mini-filesystem in ... –

LearningObjectives

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

– howgit allowsyouandapartnertoworktogether

2

Page 3: A Simple Introduction to Git: a distributed version ... · A Simple Introduction to Git: a distributed version-control system ... – how git creates a mini-filesystem in ... –

Git isadistributed version-controlsystem

• Youkeepyourfilesinarepository onyourlocalmachine.

• Yousynchronizeyourrepositorywitharepositoryonaserver.

• Ifyoumovefromonemachinetoanother,youcanpickupthechangesbysynchronizingwiththeserver.

• Ifyourpartneruploadssomechangestoyourfiles,youcanpickthoseupbysynchronizingwiththeserver.

3

Page 4: A Simple Introduction to Git: a distributed version ... · A Simple Introduction to Git: a distributed version-control system ... – how git creates a mini-filesystem in ... –

Git isadistributedversion-controlsystem

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

• Git keepstrackofthehistoryofyourcommits,soyoucangobackandlookatearlierversions,orjustgiveuponthecurrentversionandgobacksomeearlierversion.

4

Page 5: A Simple Introduction to Git: a distributed version ... · A Simple Introduction to Git: a distributed version-control system ... – how git creates a mini-filesystem in ... –

Asimplemodelofgit

• Mostgit documentationgetsintodetailsveryquickly.

• Here’saverysimplemodelofwhat’sgoingoningit.

5

Page 6: A Simple Introduction to Git: a distributed version ... · A Simple Introduction to Git: a distributed version-control system ... – how git creates a mini-filesystem in ... –

Yourfiles

my-project docs manual.docx

user_docs.docx

srcmain.rkt

module1.rkt

module2.rkt

module3.rkt

Hereareyourfiles,sittinginadirectorycalledmy-

project

6

Page 7: A Simple Introduction to Git: a distributed version ... · A Simple Introduction to Git: a distributed version-control system ... – how git creates a mini-filesystem in ... –

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

Page 8: A Simple Introduction to Git: a distributed version ... · A Simple Introduction to Git: a distributed version-control system ... – how git creates a mini-filesystem in ... –

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

Page 9: A Simple Introduction to Git: a distributed version ... · A Simple Introduction to Git: a distributed version-control system ... – how git creates a mini-filesystem in ... –

Yourworkflow(part1)

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

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

9

Page 10: A Simple Introduction to Git: a distributed version ... · A Simple Introduction to Git: a distributed version-control system ... – how git creates a mini-filesystem in ... –

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

Page 11: A Simple Introduction to Git: a distributed version ... · A Simple Introduction to Git: a distributed version-control system ... – how git creates a mini-filesystem in ... –

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

Page 12: A Simple Introduction to Git: a distributed version ... · A Simple Introduction to Git: a distributed version-control system ... – how git creates a mini-filesystem in ... –

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

Page 13: A Simple Introduction to Git: a distributed version ... · A Simple Introduction to Git: a distributed version-control system ... – how git creates a mini-filesystem in ... –

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

Page 14: A Simple Introduction to Git: a distributed version ... · A Simple Introduction to Git: a distributed version-control system ... – how git creates a mini-filesystem in ... –

WerecommendGithub Desktop

• ThisisaniceUIforgithub.• Ifyourprefer,youcanusethecommandline,oranyothergit interfaceyoulike.

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

• Werecommendthatyousetupyourreposto“alwaysrebase”.(Whenwesetupyourrepos,wewilltrytosetthemuptodothisautomatically)

14

Page 15: A Simple Introduction to Git: a distributed version ... · A Simple Introduction to Git: a distributed version-control system ... – how git creates a mini-filesystem in ... –

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

Page 16: A Simple Introduction to Git: a distributed version ... · A Simple Introduction to Git: a distributed version-control system ... – how git creates a mini-filesystem in ... –

YourworkflowwithGDsync

edit

commit

edit

commit

edit

commit

sync

Bestpractice:commityourworkwheneveryou’vegottenonepartofyourproblemworking,orbeforetryingsomethingthatmightfail.

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

16

Page 17: A Simple Introduction to Git: a distributed version ... · A Simple Introduction to Git: a distributed version-control system ... – how git creates a mini-filesystem in ... –

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

Page 18: A Simple Introduction to Git: a distributed version ... · A Simple Introduction to Git: a distributed version-control system ... – how git creates a mini-filesystem in ... –

Startingyourworksession• Here’swhatyourGithub Desktopshouldlooklikewhenyou

openitup.Observethatyourreposwillbeinthesectionlabeled“Enterprise”.

18

Page 19: A Simple Introduction to Git: a distributed version ... · A Simple Introduction to Git: a distributed version-control system ... – how git creates a mini-filesystem in ... –

WhereamI?• Theopenbluecircleindicatesthatyouarelookingatthemost

recentlocalfiles

19

Page 20: A Simple Introduction to Git: a distributed version ... · A Simple Introduction to Git: a distributed version-control system ... – how git creates a mini-filesystem in ... –

Alwaysstartbysyncing• Thiswilldownloadanychangesthatyouoryourpartnerhave

madeonothermachines

20

Page 21: A Simple Introduction to Git: a distributed version ... · A Simple Introduction to Git: a distributed version-control system ... – how git creates a mini-filesystem in ... –

Clickonadottoseeacommit• Clickingonthelastdotwillshowyouwhatwasinyourlast

commit• Thedotturnsblue

21

Page 22: A Simple Introduction to Git: a distributed version ... · A Simple Introduction to Git: a distributed version-control system ... – how git creates a mini-filesystem in ... –

• Inthisview,youcanseethefirst6charactersoftheuniqueidentifier(“theSHA”)forthiscommit

• You’llneeditforyourWorksession Report

ThisshowsyourcommitSHA

22

Page 23: A Simple Introduction to Git: a distributed version ... · A Simple Introduction to Git: a distributed version-control system ... – how git creates a mini-filesystem in ... –

Nowlet’sworkonourfile• Nowthescreenshowsanuncommittedchange.

23

Page 24: A Simple Introduction to Git: a distributed version ... · A Simple Introduction to Git: a distributed version-control system ... – how git creates a mini-filesystem in ... –

• Wewriteacommitmessage.Thenwe’llclickon“CommittoMaster”

Next,wecommitourwork

24

Page 25: A Simple Introduction to Git: a distributed version ... · A Simple Introduction to Git: a distributed version-control system ... – how git creates a mini-filesystem in ... –

• Nowitsays“Nouncommittedchanges”again.• Youcanalsoundothecommitifyouwant.

Here’swhatyou’llseeafteracommit

25

Page 26: A Simple Introduction to Git: a distributed version ... · A Simple Introduction to Git: a distributed version-control system ... – how git creates a mini-filesystem in ... –

• Clickontheopencircletoseewhatwasinyourcommit,andtorecordthecommitSHA.Here’sthatscreenagain:

BesuretorecordthecommitSHA

26

Page 27: A Simple Introduction to Git: a distributed version ... · A Simple Introduction to Git: a distributed version-control system ... – how git creates a mini-filesystem in ... –

• Yourworkisnotsavedontheserveruntilyousync.

Besuretosync!!!

27

Page 28: A Simple Introduction to Git: a distributed version ... · A Simple Introduction to Git: a distributed version-control system ... – how git creates a mini-filesystem in ... –

SubmitaWorkSessionReport• Attheendofyourwork

session,submitaworksessionreportviatheweb.

• TheURLfortheworksessionreportwillappearineachproblemset.

• ThereportwillaskfortheSHAofyourlastcommit.YoucangetthisfromtheGithub Desktop,aswe’veshownyou.

28

Page 29: A Simple Introduction to Git: a distributed version ... · A Simple Introduction to Git: a distributed version-control system ... – how git creates a mini-filesystem in ... –

Otherwaystousegit andgithub

• Therearelotsofpossiblewaystousegit andgithub.

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

• Butyoushouldbeabletogetbyjustfinewithjustasinglemasterbranch.

29

WebelieveintheKISSprinciple:“KeepItSimple,Stupid!”

Page 30: A Simple Introduction to Git: a distributed version ... · A Simple Introduction to Git: a distributed version-control system ... – how git creates a mini-filesystem in ... –

Summary

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

– howgit allowsyouandapartnertoworktogether

30