NCARB Checkout Git

42
NCARB CHECKOUT GIT

Transcript of NCARB Checkout Git

Page 1: NCARB Checkout Git

NCARBCHECKOUTGIT

Page 2: NCARB Checkout Git

TOPICSINTHISTALKIntroductionDesignGoalsArchitectureUsingGit-Basics-Branching-CollaborationGitwithVisualStudioGitHub

Page 3: NCARB Checkout Git

GITCULTUREEverythingisaFeatureBranchCommitoftenasworkprogressesDevelopersdon'taskforpermission:CloneandsendapullrequestMaintainerspickandchoosewhattomergeDelegatednetworkoftrust

Page 4: NCARB Checkout Git

HISTORYDevelopedinApril2005byLinusTorvalds

PREGITLinuxCollaboratorsworkedwithpatches

thenBitkeeperandfallout

NOWMaintainedbyJunioHamano

Page 5: NCARB Checkout Git

DESIGNGOALSDistributedReliableQuick

ACHIEVEDTHROUGHARCHITECTUREANDGOODCODE

Page 6: NCARB Checkout Git

DISTRIBUTEDTheentirerepositoryiscopied.

Repositoryworkisdoneofflinebecauseyouhavethewholerepositorywithyou.

Page 7: NCARB Checkout Git

RELIABLEEachobject'sfilenameisitshash:

easytoverify.

DISTRIBUTED==RELIABLEIfyourrepositoryislost,

justaskforanotherdeveloper'scopy.

Page 8: NCARB Checkout Git

GITFEATURE:QUICKSnapshots,notdiffs.

Fastoperationsonswitching,merging,andcommitting.

Simplearchitecturewithkernelhackerrefinements.

DISTRIBUTED==QUICKAlloperationsarelocal.

Page 9: NCARB Checkout Git

ARCHITECTURE

EACHOBJECT'SFILENAMEISITSHASH

OBJECTSFiles,Directories,Commits

POINTERSBranches,HEAD,Tags

Page 10: NCARB Checkout Git

OBJECTSHello.txt

e965047ad7c57865823c7d992b1d046ea66edf78

Hello\n

DirectoryContainingHello.txt2ea873e13e84497d7459150a0b2b662403e3bc2b

100644blobe965047ad7c57865823c7d992b1d046ea66edf78Hello.txt

CommitofDirectoryContainingHello.txt849d9a4ec0e853151ca4e8ff630feee25d701386

tree2ea873e13e84497d7459150a0b2b662403e3bc2bparent2dce1bf1497951717f34a3a0d9605436e0477832authorDAnderson<[email protected]>1375967945-0400committerDAnderson<[email protected]>1375968283-0400

CommittedHello.txt

Page 11: NCARB Checkout Git

POINTERSMasterBranch

.git/refs/heads/master

849d9a4ec0e853151ca4e8ff630feee25d701386

HEAD.git/HEAD

ref:refs/heads/master

config.git/config(snippet)

[remote"origin"]url=https://github.com/davious/PrepGit.gitfetch=+refs/heads/*:refs/remotes/origin/*[branch"master"]remote=originmerge=refs/heads/master

Page 12: NCARB Checkout Git

USINGGITBasicsBranchingCollaboration

Page 13: NCARB Checkout Git

BASICSSetupaRepositoryStageFilesCommitStagedFilesUndoChangesTagging

Page 14: NCARB Checkout Git

SETUPAREPOSITORYCREATEAREPOSITORY

gitinit

Createsarepositoryfilesysteminthe.gitsubdirectory

SETNAMEANDEMAILgitconfiguser.name"DAnderson"gitconfiguser.email"[email protected]"

Usedinallcommitfiles

Page 15: NCARB Checkout Git

Stagesfiles;filesarenowtracked.

STAGEFILESgitadd.

Furthermodificationstothesamefileremainunstageduntilthenextadd.

Showswhichfilesaretracked,whichfilesaremodified

Showsline-by-linechangesbetweenmodifiedandstaged/committed

Showsline-by-linechangesbetweenstagedandcommitted

gitstatus

gitdiff

gitdiff--cached

Page 16: NCARB Checkout Git

Amendisaneasywaytoaddtowhatwasjustcommitted

COMMITFILESgitcommit-m"Commitmessage"

Branchnowpointstonewcommitfile.Commitfilespointtopreviousparent(s).

gitcommit-m"Commitmessage"--amend

orjustredothecommitmessage

gitlog

Reviewpastcommits

Page 17: NCARB Checkout Git

UNDOINGTHINGSgitcheckout--filename1filename2gitclean-f

Revertunstagedchangedtotheirstagedorcommittedstate;cleandeleteduntrackedfiles

gitresetHEADgitresetHEADfilename1filename2

Unstagestagedfilesgitreset--hard

Throwawayallworkgitreset--hardHEAD^2

Undolasttwocommits

Page 18: NCARB Checkout Git

TAGGINGgittag-a2.0-m"MidAugustRelease"

Addsatagonbranch'slastcommit

gitdescribe2.0-12-8bd3fe1

Currentcommitdescriptionbasedonlastcreatedtag

{lasttagname}-{revisionssince}-{shorthashofcommit}

Page 19: NCARB Checkout Git

BRANCHESEthosCreatingMergingResolvingConflictsRebasingSquashing

Page 20: NCARB Checkout Git

BRANCHETHOSBranching,Checkingout,andMergingischeapandfastItkeepsthemasterbranchgoldenWebranchwithinourownrepositories;so,themainrepositoryremainsuncluttered

SO,FOREACHENDEAVOR,BRANCH

Page 21: NCARB Checkout Git

Switchesyourworkingfilestothisbranchesfiles

Shortcut:createsthebranchandchecksitout

BRANCHCREATIONgitbranchnewbranch#master,newbranch>>A;HEAD>>master

Createsanewbranch

gitcheckoutnewbranch#HEAD>>abranch

Note:Anystagedfilesremainedstaged

gitcheckout-bnewbranch#master,newbranch>>A;HEAD>>abranch

newbranchisnowyourcurrentworkingbranch

Page 22: NCARB Checkout Git

Listsbranches;starscurrentbranch

Deletesabranch

BRANCHMANAGEMENTgitbranch*masterfeature1

gitbranch-Dfeature1

Page 23: NCARB Checkout Git

MERGINGgitcheckoutmastergitmergeabranch

Mergeschangesinabranchintomaster

FAST-FORWARDMERGEWhencommitshaveonlybeenaddedtoabranch,

justpointtothebranch'scommitobject

master>>Amaster,newbranch>>Amaster>>A<-B<<newbranchA<-B<<master,newbranch

Page 24: NCARB Checkout Git

MERGINGCOMPOSITEMERGE

Whenbothbrancheshavechangedandcanbecleanlymerged,

anewcommitobjectiscreated;ithastwoparents.

B(masterwork)↙↖AD(merge)↖↙C(newbranchwork)

Page 25: NCARB Checkout Git

CONFLICTSgitmergeabranchAuto-merginghello.txtCONFLICT(content):Mergeconflictinhello.txtAutomaticmergefailed;fixconflictsandthencommittheresult.gitmergetoolgitcommit

Theresultisjustlikeacompositemerge.

TypicalConflictMarkup<<<<<<<HEADLinemodifiedinmaster=======Linemodifiedinabranch>>>>>>>abranch

gitmergeabranch/conflict:youcanhandeditit/gitadd.gitcommit

Page 26: NCARB Checkout Git

REBASING

Reconfigurebranchhistorysothatthesamechangesarebasedonadifferentcommit

Reconfiguresabranchsothatwhenmastermergesit,

itisafast-forwardmerge

B↙A⇒A←B←C↖C

gitcheckoutabranchgitrebasemaster

Page 27: NCARB Checkout Git

Bringsupanedit-listofcommitstosquashtogether

SQUASHINGWhenyouarealreadyarewithoutconflicts...

gitrebasemaster-i--autofix

Undoesallcommits,butkeepschangesstagedforacommit

Committomasterbranchinonecommit

gitreset--softmastergitcommit-m"abrancheswork,nowinonecommit"

gitcheckoutmastergitmerge--squashabranchgitcommit-m"abranchinonecommit"

Page 28: NCARB Checkout Git

COLLABORATINGCloningPullPush

Page 29: NCARB Checkout Git

CLONEgitclonehttps://github.com/ncarb/Repo.git

Init+Copiesrepository+addsremotereferences

gitremoteaddmehttps://github.com/davious/Repo.git

Addsaremote

gitfetch

Bringsdownobjectsfromremoterepositoryupdatesremotebranchstoredlocally

Page 30: NCARB Checkout Git

Shortcutfordoingafetchand

Setabranchtotrackorigin's

PULLgitpull

Shortcutfordoingafetchandmergingchangesintothebranch

gitpull--rebase

rebasingthebranchtobeafast-forwardoftheremotegitbranch-uorigin/master

masterbranch

Setanewbranchtotrackorigin'smasterbranch

gitcheckout-babranchorigin/master

Page 31: NCARB Checkout Git

Pusheslocalcommitstotheremote.

Pushesatagtoaremoterepository

PUSHgitpush[remote]

Iftherehavebeenchangessinceyourlastfetch,yourpushwillbecancelled.

gitremoteset-url--pushoriginhttps://github.com/davious/Repo.git

Changesthedefaultrepositoryyoupushtogitpush-f

Forcetheremotetoacceptout-of-syncchanges.Notusuallydonewhilecollaborating.

gitpushorigin2.0

Page 32: NCARB Checkout Git

VISUALSTUDIOINTEGRATIONmsys-gitposh-gitGitHubforWindowsSeeGitVisualStudioGitProvidergit-tfs

Page 33: NCARB Checkout Git

MSYS-GITBasicCommand-linesupport

GitBashShell

GitGUI

Page 34: NCARB Checkout Git

POSHGITPowershellEnhancedGitCommand-lineExperience

C:\Users\danderson\Dev[master+3~4-0|+0~1-0]>

Fancy,color-codedcommandpromptAuto-completedgitcommandsandargumentsbranchupstream:insync,ahead,behind,both

files:staged,unstaged+=addedfiles

~=modifiedfiles-=deletedfiles

Page 35: NCARB Checkout Git

GITHUBFORWINDOWSSimpleGitHubaccountmanagement

Appeye-candyFuntoviewhistoryFuntoviewunifieddiffsEasytosynclocalrepositorieswithGitHubrepositoriesMsys-GitandPosh-Gitarebundledinwithit

Page 36: NCARB Checkout Git

SEEGITVisualApplicationforGit

Page 37: NCARB Checkout Git

VISUALSTUDIOGITPROVIDERTeamExplorer:ChangedFiles,Commit,Push,Pull,ConflictResolutionSolutionExplorer:FileStatus,HistoryImprovementsforthcomingIntegratedwithTeamFoundationService

Note:SolutionProviderisgitaddagnostic

Page 38: NCARB Checkout Git

GIT-TFSPluginforGitcommand-line

gittfsclonehttp://tfs:8080/tfs/DefaultCollection$/Project

gitcheckout-bstorygitcommit-am"Progress"gittfspullgittfsshelve"ShelvesetName"gittfscheckintool

AllowsyoutousegitfordevelopmentwhenrepositoryisTFS

Note:CommitstoTFSasonecommit,evenwhenyouhavecommittedmultipletimes:

noneedtorebase

Page 39: NCARB Checkout Git

GITHUBPopularThrivingCommunityGreatCodeWebExperienceOrganizationSupportPullRequestsSophisticatedCodeReviewRepositoryWikiIssueTrackingLowCostWebApiTeamCityintegration

Page 40: NCARB Checkout Git

GITHUBINTEGRATIONDEVELOPEREXPERIENCE

trackmainrepositorypullrequestwhenreadyforreviewrequestisverfiedbyTeamCityrequeststartscoderevieweasytocommentdirectlyoncodechangesinGitHubGitHubprovidesemailnotificationsonbuildstatusandcodereviewabilitytopushbranchestoindividualaccounttocollaboratewithteammembers

Page 41: NCARB Checkout Git

GITHUBINTEGRATIONREVIEWEREXPERIENCE

PullRequestsarecheckedbyTeamCity;notificationsinpullrequestcommentsEasilyseeifrequestwillmergewithoutconflictsCanuseJohnResig'sNode.jsmodulePulleytorebasepullrequestsandcloseit

Page 42: NCARB Checkout Git

CONCLUSIONGitisawell-designedversioncontrolsystem.

MicrosoftsupportsGit.

Weareusinggitlocallywithgit-tfsrightnow.

GitHuboffersasophisticatedrepositoryservice.

TeamCitysupportsGitandGitHub.

WecouldbeusingGitHubrightaboutnow.