So#ware(Project Lecture'3 Wouter'Swierstra So#ware(project(–(Lecture(3 1
Last%&me • Scrum'planning • Product'backlog So#ware(project(–(Lecture(3 2
Working(effec,vely(with(git(and(GitHub. So#ware(project(–(Lecture(3 3
Collabora've*so,ware*development You$have$two$weeks$to$finish$your$user$stories. And$need$to$give$a$demo$at$the$end. How$can$you$develop$different$stories$in$parallel$without$ breaking$your$working$prototype? So#ware(project(–(Lecture(3 4
Version(control So#ware(project(–(Lecture(3 5
What%is%git? • A#popular,#powerful#distributed#file#version#control#system • It#is#free#and#obtainable#from#git;scm.com • Originally#developed#to#manage#the#Linux#kernel • An#esBmated#27#percent#of#professional#developers#uses#Git# (May#'12). So#ware(project(–(Lecture(3 6
Ge#ng&to&grips&with&git • Git%is%a%very%powerful%tool%with%many%different%features. • The%user%interface%takes%some%ge<ng%used%to... • When%used%correctly,%it%can%be%extremely%effecAve. • If%you%screw%up,%there%is%usually%a%way%to%undo%your%changes. So#ware(project(–(Lecture(3 7
Star%ng(a(new(repo $ git init Initialized empty Git repository in .git/ Add#the#README.md#file#to#the#repository $ git add README.md Commit&the&changes&you&made&to&README.md $ git commit -m "Added README.md" So#ware(project(–(Lecture(3 8
Cloning'an'exis,ng'repository To#get#your#hands#on#a#copy#of#an#exis4ng#repository#use: $ git clone git://github.com/wouter-swierstra/SoftwareProject Note%that% git clone %supports%several%different%protocols,% including%SSH. So#ware(project(–(Lecture(3 9
Git$vs$Svn Git$is$a$ distributed $version$control$system: • a#copy#of#a#repository#can#share#changes#with#any#other#copy. • almost#all#commands#operate#on#your# local%copy • sharing#changes#with#others#happens#in#two#steps: • commi8ng#your#changes#locally • pushing#these#changes#to#a#remote#server So#ware(project(–(Lecture(3 10
Git$terminology Picture(from(Sco-(Chacon's( Pro$Git . So#ware(project(–(Lecture(3 11
Git$status $ git status # On branch master nothing to commit (working directory clean) $ emacs 04-slides.md $ git status # On branch master # Untracked files: # (use "git add <file>..." to include in what will be committed) # # 04-slides.md So#ware(project(–(Lecture(3 12
Adding&new&files $ git add 04-slides.md $ git status # On branch master # Changes to be committed: # (use "git reset HEAD <file>..." to unstage) # # new file: 04-slides.md So#ware(project(–(Lecture(3 13
Staging'modified'files Similarly,)we)can)stage)modified)files)using) git add . $ emacs README.md $ git add README.md # On branch master # Changes to be committed: # (use "git reset HEAD <file>..." to unstage) # # new file: 04-slides.md # modified: README.md Git$gives$you$control$over$which$files$to$include$in$a$single$commit. So#ware(project(–(Lecture(3 14
Pro$%p:(.gi%gnore(to(minimize(noise Generated(binaries,(documenta1on,(and(so(forth(are(not(under( version(control,(but(keep(showing(up(when(you(run( git status . You$can$have$a$ .gitignore $file,$lis0ng$the$files,$directories,$and$ pa6erns$that$you$want$git$to$ignore: $ cat .gitignore *.pdf .DS_Store build/ So#ware(project(–(Lecture(3 15
Commi%ng(your(changes The$ git commit $command$commits$all$the$staged$changes. $ git commit -m "Added 04-slides.md; updated README.md" [master 76d15ab] Added 04-slides.md; updated README.md 1 files changed, 1 insertions(+), 0 deletions(-) create mode 100644 04-slides.md These%changes%are%recorded% locally %but%not%yet%shared%with%others. So#ware(project(–(Lecture(3 16
Not$men(oned • git mv "to"rename"files,"without"losing"their"history • git rm "to"remove"files"from"the"repository • git commit -a "to"record"all"your"changes"to"tracked"files • git log "to"get"an"overview"of"recent"changes • git reset "to"undo"changes So#ware(project(–(Lecture(3 17
Sharing(your(changes All#these#commands#operate#on#your#local#copy#of#the#repository. Nothing(is(shared(with(others(yet. • git pull "–"pulls"in"changes"from"some"other"repository • git push "–"pushes"your"changes"to"another"repository These%commands%communicate%with% remote&repositories . So#ware(project(–(Lecture(3 18
Basic&usage:&git&push $ git clone git://github.com/wouter-swierstra/SoftwareProject ... $ emacs 04-slides.md $ git commit -am "Updated slides on git" $ git push So#ware(project(–(Lecture(3 19
Showing(remote(repositories $ git clone git://github.com/wouter-swierstra/SoftwareProject ... $ git remote -v origin git://github.com/wouter-swierstra/SoftwareProject (push) origin git://github.com/wouter-swierstra/SoftwareProject (fetch) So#ware(project(–(Lecture(3 20
Pull$changes$from$remote$repositories $ git pull remote: Counting objects: 45, done. remote: Total 45 (delta 2), reused 2 (delta 2), pack-reused 43 Unpacking objects: 100% (45/45), done. From https://git.science.uu.nl/swier004/my-repository 543d40c..8497463 master -> origin/master * [new branch] redirect -> origin/redirect Updating 543d40c..8497463 Fast-forward ... So#ware(project(–(Lecture(3 21
The$real$challenge This%covers%the%very%basic% git %opera0ons. You$can$now$collaborate$on$a$single$codebase. But$collabora+ng$ effec$vely $is$not$easy. So#ware(project(–(Lecture(3 22
GitLab The$university$provides$a$repository$hos1ng$service,$GitLab: • Repository • Issue-tracker • Wiki • Useful-graphical-interface Many%complex,%yet%common,%opera0ons%can%be%done%through%the% GitLab%GUI. So#ware(project(–(Lecture(3 23
Gitlab So#ware(project(–(Lecture(3 24
Branching Git$makes$it$ very%easy $to$work$on$different$versions$of$your$ so4ware. Use$branches$to$isolate$different$all$the$stories$being$developed$in$ an$itera4on. Create&one&branch&per&story&at&the&beginning&of&the&itera2on. Merge%each%branch%back%to%master%at%the%end%of%the%itera3on. So#ware(project(–(Lecture(3 25
Golden'rules 1. The&master&branch&may&only&contain&code&that&is&tested,& reviewed&and&ready&to&be&released. 2. Only&commit&code&that&compiles,&even&in&experimental&branches. 3. No&branch&lives&more&than&three&itera=ons (the&master&branch&excluded). 4. Create&pull&requests&for&every&new&branch.&Only&merge&your& changes&if&everyone&is&happy. So#ware(project(–(Lecture(3 26
So#ware(project(–(Lecture(3 27
Working(with(merge(requests Create&branch&with&your&feature&new&feature git checkout -b new_feature ... git commit -am "My feature is ready" git push origin new_feature Create&a&merge&request&from&this&commit. Members'of'your'team'can'review'the'code'&'merge'it'with'main. So#ware(project(–(Lecture(3 28
Merge%requests%demo So#ware(project(–(Lecture(3 29
Working(with(merge(requests One$or$two$people$responsible$for$merging$branches$with$main. Before&a&branch&is&merged&with&the&main&branch,&there&should&be&a& code&review. Use$the$forum$for$discussion$if$there$are$issues$with$the implementa4on,$execu4on,$tests,$etc. So#ware(project(–(Lecture(3 30
Code%reviews • Does&the&code&work? • Is&it&easy&to&understand&and&clearly&structured? • Does&it&adhere&to&coding&conven8ons? • Are&there&comments? • Are&there&any&open&TODOs&or&obviously&unfinished&methods? • Is&there&an&automated&test&for&this&feature/bug? So#ware(project(–(Lecture(3 31
Code%reviews If#the#answer#to#any#of#these#ques0ons#is#no#–#don't#merge. Merging'with'master'exposes'your'work'to'the'rest'of'the'team. Breaking)their)work)means)was0ng) everybody's )0me. Inves&ng(in(quality(assurance(now(will(be(invaluable(later. So#ware(project(–(Lecture(3 32
Wri$ng'good'comments • Don't'explain'obvious'details,'instead'focus'on'the'key'ideas. • Bad:' \\This for loop iterates over the array • Be<er:' \\This method computes the sum of a non- empty array storing positive integers • Document'invariants,'assump?ons,'unusual'behaviour'and' corner'cases. • Explain'the'design'decisions'you'made'that'lead'to'this'code. So#ware(project(–(Lecture(3 33
Wri$ng'good'comments • The%goal%is%not%to%explain%the%micro3details%on%every%line%of% code... • ...%but%rather%to%help%a%new%reader%understand%the%big%picture%of% what%is%going%on. So#ware(project(–(Lecture(3 34
Further'reading • Lessons'in'so)ware'development • Pro4git • A'tutorial'on'merge'requests'and'issues'in'Gitlab • GitLab'introduc<on'videos'on'Youtube • Lessons'learned'in'so)ware'development So#ware(project(–(Lecture(3 35
So#ware(project(–(Lecture(3 36
Recommend
More recommend