RMG Study Group · 23/02/2015  · Getting started: create a local repo Two common scenarios: (only...

20
RMG Study Group Basics of Git Nathan Yee 2/23/2015 1

Transcript of RMG Study Group · 23/02/2015  · Getting started: create a local repo Two common scenarios: (only...

Page 1: RMG Study Group · 23/02/2015  · Getting started: create a local repo Two common scenarios: (only do one of these) a)To clone an already existing repo to your current directory:

RMGStudyGroupBasicsofGit

NathanYee2/23/2015

1

Page 2: RMG Study Group · 23/02/2015  · Getting started: create a local repo Two common scenarios: (only do one of these) a)To clone an already existing repo to your current directory:

KeyURLs

§ http://www.github.com/GreenGroup§ Git repositoryofallRMG-Py code

§ http://greengroup.github.io/RMG-Py/§ OnlineversionofthecurrentRMG-Py documentation

§ http://rmg.mit.edu§ OfficialRMG-Py documentation,thermodynamicsandkineticsdatabasebrowser,andwebtools

§ http://dev.rmg.mit.edu§ Developmentalversionofrmg.mit.edu withlatestfeaturesandpotentialbugs

§ Touse,add18.172.0.124 dev.rmg.mit.edu tohostsfileinyouroperatingsystem

2

Page 3: RMG Study Group · 23/02/2015  · Getting started: create a local repo Two common scenarios: (only do one of these) a)To clone an already existing repo to your current directory:

Git

§ Git isaversioncontroltool§ Multipleuserscaneditmultiplecopiesofcode§ Singleusercancreatemultiplebranchesforasinglerepository

§ Onlinedetailedtutorial:§ http://git-scm.com/book

§ Wheretofindprogramstohelpyouusegit:§ http://git-scm.com/downloads

3

Page 4: RMG Study Group · 23/02/2015  · Getting started: create a local repo Two common scenarios: (only do one of these) a)To clone an already existing repo to your current directory:

Gettingstarted:createalocalrepo

Twocommonscenarios:(onlydooneofthese)a) Tocloneanalreadyexistingrepotoyourcurrent

directory:$ git clone <url> [local dir name]Thiswillcreateadirectorynamedlocaldir name,containingaworkingcopyofthefilesfromtherepo,anda.git directory(usedtoholdthestagingareaandyouractualrepo)

b) TocreateaGit repoinyourcurrentdirectory:$ git initThiswillcreatea.git directoryinyourcurrentdirectory.Thenyoucancommitfilesinthatdirectoryintotherepo:$ git add file1.java$ git commit –m “initial project version”

4

Page 5: RMG Study Group · 23/02/2015  · Getting started: create a local repo Two common scenarios: (only do one of these) a)To clone an already existing repo to your current directory:

BasicGit Workflow

1. Modify filesinyourworkingdirectory.2. Stage files,addingsnapshotsofthemto

yourstagingarea.3. Makeacommit,whichtakesthefilesas

theyareinthestagingareaandstoresthatsnapshotpermanentlytoyourGit directory.

5

Page 6: RMG Study Group · 23/02/2015  · Getting started: create a local repo Two common scenarios: (only do one of these) a)To clone an already existing repo to your current directory:

Git filelifecycle

Notes:Ifaparticularversionofafileisinthegit directory,it’sconsideredcommitted.Ifit’smodifiedbuthasbeenaddedtothestagingarea,itisstaged.Ifitwaschanged sinceitwascheckedoutbuthasnot beenstaged,itismodified.

6

Page 7: RMG Study Group · 23/02/2015  · Getting started: create a local repo Two common scenarios: (only do one of these) a)To clone an already existing repo to your current directory:

LocalCommits

1. ‘git status’tocheckwhichfilesaremodified-’git diff<filename>’showsline-by-linechanges

2. ‘git add<filename>’stagesalldesiredfiles3. ‘git commit’createsnewsnapshotofstagedfiles

andaddstothehistory4. ‘git log’pullsuphistoryofbranch;shouldseeyour

latestcommit

7

Page 8: RMG Study Group · 23/02/2015  · Getting started: create a local repo Two common scenarios: (only do one of these) a)To clone an already existing repo to your current directory:

WritingCommitMessages

§ Firstlineis<80charactersummary§ Followedbydetaileddescription

§ Listofalladditions/changes§ Motivation§ Implementationdetails

§ Examplesofbadgit messages:§ “Typo”§ “Adddatabaseentries”

§ Aftersavingmessageauniquecommitstringiscreatedforeachentry

8

Page 9: RMG Study Group · 23/02/2015  · Getting started: create a local repo Two common scenarios: (only do one of these) a)To clone an already existing repo to your current directory:

Git Branches

§ Branchesstartanewhistorytomakeexperimentalfeatures

§ Allowsexperimentationwithoutfearof“messingupthecode”

9

Page 10: RMG Study Group · 23/02/2015  · Getting started: create a local repo Two common scenarios: (only do one of these) a)To clone an already existing repo to your current directory:

CommandsusedwithBranches

§ Git branch:pullsupalistofallthebranches§ Git branch<newbranch>:forksanewfromthecurrenthead

10

Fromthiscommit:Git branchnice_feature

Page 11: RMG Study Group · 23/02/2015  · Getting started: create a local repo Two common scenarios: (only do one of these) a)To clone an already existing repo to your current directory:

CommandsusedwithBranches

§ Git checkout<location>:movestheheadtolocation(canbeacommitstringorbranchname)

§ Git merge<branch>:mergesallcommitsfrombranch

11

Git checkoutabcd1234bringsyouherefrom

anywhereelse

Fromhere:Git mergenice_featureCommitsthenicefeature

tomaster

Page 12: RMG Study Group · 23/02/2015  · Getting started: create a local repo Two common scenarios: (only do one of these) a)To clone an already existing repo to your current directory:

AdvancedHistoryControl:Rebase

§ Normallywhenmerging:makeanewcommitthatincorporatesallchanges

§ Fromexperiment:Git rebasemastermergesandchronologicallyreorderscommits

12

Page 13: RMG Study Group · 23/02/2015  · Getting started: create a local repo Two common scenarios: (only do one of these) a)To clone an already existing repo to your current directory:

FullControl:Git rebaseinteractive

§ Git rebase–i <commitstring>:opensinteractiveGUIthatallowsfullrewritingofhistory§ Deleteorreordercommits§ Squashcommitstogether§ Makechangestoacommit§ Rewritecommitmessages

§ WARNING:donotusethistorewritehistoryyouhavepushedtoofficial

13

Page 14: RMG Study Group · 23/02/2015  · Getting started: create a local repo Two common scenarios: (only do one of these) a)To clone an already existing repo to your current directory:

GreenGroupRepos

14

OfficialGreenGroupRepo

• https://github.com/GreenGroup/• Forofficialdistribution

PersonalGithub Repo

-Sharingdevelopmentswithotherusers-Backupofin-progresscode

LocalRepositories

-Runningjobs-Codedevelopmentanddebugging

Gitp

ush

PullRe

quest

Gitpull Gitpull

Page 15: RMG Study Group · 23/02/2015  · Getting started: create a local repo Two common scenarios: (only do one of these) a)To clone an already existing repo to your current directory:

SettingupRemoteRepos

§ Git remoteadd<remotename><url>

§ IfyouoriginallyforkedfromGreenGroup official:§ Git remoterenameoriginofficial§ CreateyourownforkonGithub andnameorigin

15

Page 16: RMG Study Group · 23/02/2015  · Getting started: create a local repo Two common scenarios: (only do one of these) a)To clone an already existing repo to your current directory:

Pulling/PushingCommits

§ Eachrepohasitsownbranches§ Commandsforpullingandpushingcallbranches§ Mostcommoncall:git pullofficialmaster§ Forpushing:git pushoriginnew_feature

§ Goodideatotrytokeepbranchnamesconsistent

16

Page 17: RMG Study Group · 23/02/2015  · Getting started: create a local repo Two common scenarios: (only do one of these) a)To clone an already existing repo to your current directory:

KeepingOfficialRepoClean

§ Topushacommittoofficial:1. CleanupyourcommithistorywithGit rebase–i

<firstnewcommit>2. Checkthatyourcurrentcommitisupdatedupto

theofficialGit pull–rebaseofficialmaster3. PushtoyourpersonalGitHubrepo:Git push

originnew_feature4. Makeformalpullrequest fromyourGitHub

Repo

17

Page 18: RMG Study Group · 23/02/2015  · Getting started: create a local repo Two common scenarios: (only do one of these) a)To clone an already existing repo to your current directory:

CommonGit commands

18

Page 19: RMG Study Group · 23/02/2015  · Getting started: create a local repo Two common scenarios: (only do one of these) a)To clone an already existing repo to your current directory:

YoucandoallofthisusingGit-cola:apowerfulGUIinterface

Commitorrevertspecificlines.Stagefilesandwritecommitmessagesgraphically.Amendcommits.

19

Page 20: RMG Study Group · 23/02/2015  · Getting started: create a local repo Two common scenarios: (only do one of these) a)To clone an already existing repo to your current directory:

Git-cola:apowerfulGUInterface

Visualizepastcommithistoryandrepositorybranches.(Greatfortrackingspecificcodechanges.)

AvailableforWindows,Mac,andLinux!

20