Slide 1

Slide 1 text

Incorporating Version Control into Programming Courses Tommy MacWilliam [email protected]

Slide 2

Slide 2 text

No content

Slide 3

Slide 3 text

Source Control Management

Slide 4

Slide 4 text

What? • track revisions of files • review past versions of projects • collaborate with peers and staff

Slide 5

Slide 5 text

What? • CVS • SVN • Git • Mercurial • Bazaar • ...

Slide 6

Slide 6 text

Students: Why? • “I need to work on a project with a partner”

Slide 7

Slide 7 text

Students: Why? • “I need to work on a project with a partner” • “It was working a few hours ago, but I broke it”

Slide 8

Slide 8 text

Students: Why? • “I need to work on a project with a partner” • “It was working a few hours ago, but I broke it” • “I want to back up my code so I can work on another machine”

Slide 9

Slide 9 text

Staff: Why? • “I want to collect homework submissions on my server”

Slide 10

Slide 10 text

Staff: Why? • “I want to collect homework submissions on my server” • “I want to allow students to review each others’ code”

Slide 11

Slide 11 text

Staff: Why? • “I want to collect homework submissions on my server” • “I want to allow students to review each others’ code” • “I want to distribute updates to distribution code”

Slide 12

Slide 12 text

Vocabulary • repository: project containing source code files • commit: snapshot of a project in time • log: history of commits for a project • branch: independent set of changes • remote: server hosting code • tag: human-readable name for a commit

Slide 13

Slide 13 text

SCM Tools • centralized • all commits go to one repository • decentralized • commits go to developers’ individual repositories

Slide 14

Slide 14 text

SVN

Slide 15

Slide 15 text

SVN with Google Code

Slide 16

Slide 16 text

No content

Slide 17

Slide 17 text

svn checkout https://project.googlecode.com/svn/trunk/ project --username [email protected]

Slide 18

Slide 18 text

Generated Password

Slide 19

Slide 19 text

https://code.google.com/hosting/settings

Slide 20

Slide 20 text

Repository Conventions • trunk: source code • branches: independent sets of changes • tags: named commits

Slide 21

Slide 21 text

svn add pset1.c

Slide 22

Slide 22 text

svn rm pset1.c

Slide 23

Slide 23 text

svn status

Slide 24

Slide 24 text

svn commit -m “done!”

Slide 25

Slide 25 text

svn update

Slide 26

Slide 26 text

svn log

Slide 27

Slide 27 text

Workflow • student creates and checks out repository • student adds, commits files to repository • staff updates from repository to view files

Slide 28

Slide 28 text

Basic SVN Workflow • create repository • svn checkout https://project.googlecode.com/svn/ • edit pset1.c • svn add pset1.c • svn commit -m “done!”

Slide 29

Slide 29 text

Practice! • create a new SVN repository called yourname-sigcse • checkout the repository to ~/svn/student1 • create a file called pset1.c • add and commit pset1.c to the pset1 repo • add and commit test.c to the pset1 repo • view the history of commits

Slide 30

Slide 30 text

svn diff

Slide 31

Slide 31 text

svn diff -r 1:2

Slide 32

Slide 32 text

Practice! • make changes to pset1.c without committing, then view the changes • commit the changes and compare to previous revision • compare the last revision to the first revision • search all commit logs for the word “done”

Slide 33

Slide 33 text

svn checkout -r 123

Slide 34

Slide 34 text

svn update -r 123

Slide 35

Slide 35 text

Practice! • roll back to the first revision • check out a new copy of pset1, starting at the second revision

Slide 36

Slide 36 text

SVN Collaboration • check out pset1 (again) to ~/svn/student2 • make a change and commit as student2 • update the repository as student1

Slide 37

Slide 37 text

Alice svnadmin create pset1 Bob

Slide 38

Slide 38 text

Alice svn co https://host/pset1 Bob

Slide 39

Slide 39 text

Alice svn co https://host/pset1 Bob

Slide 40

Slide 40 text

Alice svn co https://host/pset1 Bob

Slide 41

Slide 41 text

Alice svn co https://host/pset1 Bob

Slide 42

Slide 42 text

Alice svn commit -m “done” Bob

Slide 43

Slide 43 text

Alice svn commit -m “done” Bob

Slide 44

Slide 44 text

Alice svn up Bob

Slide 45

Slide 45 text

Alice svn up Bob

Slide 46

Slide 46 text

Merge Conflicts • students commit incompatible changes • cannot commit until conflicts are resolved

Slide 47

Slide 47 text

Creating a Merge Conflict • student1 edits pset1.c to say “here comes a conflict” • student1 commits to pset1 repo • student2 edits pset1.c to say “I don’t like conflict” • student2 tries to commit

Slide 48

Slide 48 text

Conflict discovered in '~/svn/student2/pset1/file.c'. Select: (p) postpone, (df) diff-full, (e) edit, (mc) mine-conflict, (tc) theirs-conflict, (s) show all options: d

Slide 49

Slide 49 text

Resolving a Merge Conflict • don’t panic! • mc: keep my changes to the file • tc: keep their changes to the file • e: manually edit conflicted file • p: view files that caused conflict separately

Slide 50

Slide 50 text

<<<<<<< this is student1 ======= this is student2 >>>>>>> Single File Resolution

Slide 51

Slide 51 text

jharvard@appliance (~/svn/student2/pset1): ls file.c file.c.mine file.c.r3 Multiple File Resolution

Slide 52

Slide 52 text

Resolving a Merge Conflict • don’t panic!

Slide 53

Slide 53 text

Practice! • edit student1/pset1.c to say “here comes a conflict” • commit from student1/pset1 • edit student2/pset1.c to say “I don’t like conflict” • commit from student2/pset1 • press “e” to edit as a single file • repeat, but press “p” to resolve conflict!

Slide 54

Slide 54 text

Tags • human-readable aliases for commits • software releases, betas, submissions

Slide 55

Slide 55 text

svn cp https://project.googlecode.com/svn/trunk/ https://project.googlecode.com/svn/tags/1.0

Slide 56

Slide 56 text

Branches

Slide 57

Slide 57 text

Branches • one partner wants to try something out

Slide 58

Slide 58 text

Branches • one partner wants to try something out • develop a feature independently of project

Slide 59

Slide 59 text

Branches • one partner wants to try something out • develop a feature independently of project • staff make changes during feedback process

Slide 60

Slide 60 text

svn cp https://project.googlecode.com/svn/trunk/ https://project.googlecode.com/svn/branches/test

Slide 61

Slide 61 text

Branches • independent sets of changes • changes on one branch don’t affect other branches • switching between branches changes working copy

Slide 62

Slide 62 text

svn switch https://project.googlecode.com/svn/branches/test

Slide 63

Slide 63 text

svn rm https://project.googlecode.com/svn/branches/test

Slide 64

Slide 64 text

Practice! • create a branch called “test” • switch to the branch • make changes and commit • switch back to trunk • delete branch “test”

Slide 65

Slide 65 text

SVN on GitHub

Slide 66

Slide 66 text

SVN on GitHub • svn co --depth empty https://github.com/you/project • svn up trunk • edit files, svn add, svn commit

Slide 67

Slide 67 text

Git

Slide 68

Slide 68 text

git config --global user.name “Tommy MacWilliam”

Slide 69

Slide 69 text

git config --global user.email [email protected]

Slide 70

Slide 70 text

git init

Slide 71

Slide 71 text

git add pset1.c

Slide 72

Slide 72 text

git add --all

Slide 73

Slide 73 text

git status

Slide 74

Slide 74 text

git commit -m “done!”

Slide 75

Slide 75 text

git log

Slide 76

Slide 76 text

5aeebab117b892fa42002146e4c62be676bc4621 b43b0ad1e8108e7ab870d7a54feac93ae8b8600e 461476587780aa9fa5611ea6dc3912c146a91760 Commit ID

Slide 77

Slide 77 text

5aeebab117b892fa42002146e4c62be676bc4621 b43b0ad1e8108e7ab870d7a54feac93ae8b8600e 461476587780aa9fa5611ea6dc3912c146a91760 Commit ID HEAD

Slide 78

Slide 78 text

Practice! • create a new repository in ~/git/pset1 • create a file called pset1.c • add and commit pset1.c • make more changes to pset1.c • add and commit pset1.c again

Slide 79

Slide 79 text

Git on GitHub

Slide 80

Slide 80 text

SSH Keys

Slide 81

Slide 81 text

ssh-keygen

Slide 82

Slide 82 text

No content

Slide 83

Slide 83 text

git clone [email protected]:you/project

Slide 84

Slide 84 text

git remote

Slide 85

Slide 85 text

git remote add origin url

Slide 86

Slide 86 text

git push origin master

Slide 87

Slide 87 text

Basic Git Workflow • staff (or students) create remote repositories • students • clone repository • add and commit changes • push changes to remote repository

Slide 88

Slide 88 text

Practice! • create a GitHub repository • clone the repository • create pset1.c, then add and commit it • push pset1.c to the remote repository

Slide 89

Slide 89 text

git show

Slide 90

Slide 90 text

git show b43b0

Slide 91

Slide 91 text

git diff HEAD

Slide 92

Slide 92 text

git diff b43b0 5aeeb

Slide 93

Slide 93 text

Practice! • make changes to pset1.c without committing, then view the changes • commit the changes and compare to previous revision • compare the last revision to the first revision • search all commit logs for the word “done”

Slide 94

Slide 94 text

git checkout b43b0

Slide 95

Slide 95 text

git checkout b43b0 pset1.c

Slide 96

Slide 96 text

git checkout master

Slide 97

Slide 97 text

git reset --hard

Slide 98

Slide 98 text

Practice! • roll back to the first revision • roll only one file back to the second revision • fast-forward to the current state again

Slide 99

Slide 99 text

git revert b43b0

Slide 100

Slide 100 text

5aeeb b43b0 46147

Slide 101

Slide 101 text

5aeeb b43b0 46147 a45bc git revert 46147

Slide 102

Slide 102 text

Practice! • undo the changes in your last commit • undo the commit that undoes that commit

Slide 103

Slide 103 text

git tag done

Slide 104

Slide 104 text

git push --tags

Slide 105

Slide 105 text

git tag

Slide 106

Slide 106 text

git tag -l “1.*”

Slide 107

Slide 107 text

Practice! • create a tag called “1.0” • commit new changes • create a tag called “1.1” • view tags

Slide 108

Slide 108 text

git branch

Slide 109

Slide 109 text

git branch test

Slide 110

Slide 110 text

git checkout test

Slide 111

Slide 111 text

5aeeb b43b0 46147 master

Slide 112

Slide 112 text

5aeeb b43b0 46147 master f862f 36223 test git branch test

Slide 113

Slide 113 text

git checkout master

Slide 114

Slide 114 text

git merge

Slide 115

Slide 115 text

5aeeb b43b0 46147 f862f 36223 git branch test a34bc git merge test

Slide 116

Slide 116 text

git branch -D test

Slide 117

Slide 117 text

Practice! • create a branch called “test” • switch to the test branch • make and commit changes • switch to the master branch • merge changes from the test branch • delete the test branch

Slide 118

Slide 118 text

5aeeb b43b0 46147 f862f 36223 master test git branch test

Slide 119

Slide 119 text

5aeeb b43b0 46147 f862f 36223 master git rebase

Slide 120

Slide 120 text

Practice! • create a branch called “test2” • switch to the test2 branch • make and commit changes • switch to the master branch • rebase changes from the test2 branch • delete the test2 branch

Slide 121

Slide 121 text

Collaborating with Git • students have their own local repositories • students commit, branch, etc. on local repositories • students push to and pull from a shared repository

Slide 122

Slide 122 text

git pull origin master

Slide 123

Slide 123 text

git pull --rebase

Slide 124

Slide 124 text

Alice Bob git init git add --all git commit

Slide 125

Slide 125 text

Alice git remote add origin url git push origin master Bob

Slide 126

Slide 126 text

Alice git remote add origin url git push origin master Bob

Slide 127

Slide 127 text

Alice git clone url Bob

Slide 128

Slide 128 text

Alice git clone url Bob

Slide 129

Slide 129 text

Alice git add --all git commit Bob

Slide 130

Slide 130 text

Alice git push origin master Bob

Slide 131

Slide 131 text

Alice Bob git push origin master

Slide 132

Slide 132 text

Alice git pull origin master Bob

Slide 133

Slide 133 text

Alice Bob git pull origin master

Slide 134

Slide 134 text

Practice! • create a pset2 repository on GitHub • clone the repository in ~/git/student1/pset2 • add, commit, and push a change • clone the repository in ~/git/student2/pset2 • add, commit, and push a change • pull the change from ~/git/student1/pset2

Slide 135

Slide 135 text

Merge Conflicts • don’t panic! • git status shows conflicted files • git add files to resolve conflicts

Slide 136

Slide 136 text

Resolving Conflicts <<<<<<< this is from test ======= this is from master >>>>>>>

Slide 137

Slide 137 text

Creating a Merge Conflict • student1 edits pset2.c to say “here comes a conflict” • student1 commits and pushes to pset2 repo • student2 edits pset2.c to say “I don’t like conflict” • student2 commits, tries to push

Slide 138

Slide 138 text

Resolving using Merge • fix conflicts • git add --all • git commit -m “merge”

Slide 139

Slide 139 text

Resolving using Rebase • fix conflicts • git add --all • git rebase --continue

Slide 140

Slide 140 text

Git on BitBucket

Slide 141

Slide 141 text

Using SCM in Programming Courses

Slide 142

Slide 142 text

Using Google Code • each student creates repository for each project • students add staff as collaborators

Slide 143

Slide 143 text

No content

Slide 144

Slide 144 text

Using GitHub • https://github.com/edu • each student creates repository for each project • students add staff as collaborators

Slide 145

Slide 145 text

No content

Slide 146

Slide 146 text

Using BitBucket • unlimited free private repositories! • same process as GitHub

Slide 147

Slide 147 text

Hosting SVN • svnadmin create --fs-type fsfs pset1 • repo/conf/svnserve.conf • svnserve

Slide 148

Slide 148 text

Hosting Git • https://github.com/sitaramc/gitolite • http://scie.nti.st/2007/11/14/hosting-git- repositories-the-easy-and-secure-way/

Slide 149

Slide 149 text

Repository-Based • each project is a separate repository • students collaborate on same hosted repository • if projects are totally separate, makes sense • if projects build on each other, makes less sense

Slide 150

Slide 150 text

Branch-Based • each student creates one repository for the course • each project is a different branch • if projects build on each other, makes sense • if projects are totally separate, makes less sense

Slide 151

Slide 151 text

Distributing Code • each student: • create repository on GitHub • git clone git://github.com/course/pset1.git • git remote rm origin • git remote add origin [email protected]/student/ pset1.git • git remote add distro git://github.com/course/ pset1.git

Slide 152

Slide 152 text

Submitting Code • students • git tag submission • git push --tags • staff • git checkout submission

Slide 153

Slide 153 text

When Disaster Strikes • svn revert --recursive . • git reset --hard

Slide 154

Slide 154 text

When Disaster Really Strikes • rm -rf .git • find . -type d -name .svn -exec rm -rf {} \;

Slide 155

Slide 155 text

Potential Pitfalls • merge conflicts prevent pushes! • don’t panic • one minute before the deadline, still don’t panic • distinguish between submission and version control? • have a backup submission plan!

Slide 156

Slide 156 text

Potential Pitfalls • commit timestamps are set by the client! • tags can be deleted and moved around • if new to SCM, submission process is very complicated • if using SCM, then teach SCM

Slide 157

Slide 157 text

Hooks • small scripts that are triggered by SCM events • post-receive: whenever a push is received

Slide 158

Slide 158 text

Automating Processes • http://developer.github.com/v3/ • https://confluence.atlassian.com/display/ BITBUCKET/Using+the+Bitbucket+REST +APIs

Slide 159

Slide 159 text

version50

Slide 160

Slide 160 text

gem install version50

Slide 161

Slide 161 text

v50 create

Slide 162

Slide 162 text

v50 status

Slide 163

Slide 163 text

v50 save

Slide 164

Slide 164 text

v50 history

Slide 165

Slide 165 text

v50 warp

Slide 166

Slide 166 text

v50 recover

Slide 167

Slide 167 text

v50 download

Slide 168

Slide 168 text

speakerdeck.com/tmacwill

Slide 169

Slide 169 text

Incorporating Version Control into Programming Courses Tommy MacWilliam [email protected]