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”
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”
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
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
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”
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
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
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
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!
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
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”
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
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
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
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
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
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
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
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!
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