Version Control with Git./prs/15-441-F13/lectures/r03-version-control.pdf · Version Control with...

28
Carnegie Mellon University Computer Science Department 1/28 Version Control with Git Ben Wasserman ([email protected]) 15-441 Computer Networks Recitation 3

Transcript of Version Control with Git./prs/15-441-F13/lectures/r03-version-control.pdf · Version Control with...

Page 1: Version Control with Git./prs/15-441-F13/lectures/r03-version-control.pdf · Version Control with Git Ben Wasserman (benjamin@cmu.edu) 15-441 Computer Networks Recitation 3 . Carnegie

Carnegie Mellon University Computer Science Department

1/28

Version Control with Git

Ben Wasserman ([email protected])

15-441 Computer Networks

Recitation 3

Page 2: Version Control with Git./prs/15-441-F13/lectures/r03-version-control.pdf · Version Control with Git Ben Wasserman (benjamin@cmu.edu) 15-441 Computer Networks Recitation 3 . Carnegie

Carnegie Mellon University Computer Science Department

2/28

What is version control?

Revisit previous code versions

Backup projects

Work with others

Find where things broke

Page 3: Version Control with Git./prs/15-441-F13/lectures/r03-version-control.pdf · Version Control with Git Ben Wasserman (benjamin@cmu.edu) 15-441 Computer Networks Recitation 3 . Carnegie

Carnegie Mellon University Computer Science Department

3/28

Version Control Workflow

Check for any remote updates

Do your work

Test your work

Check differences, try to isolate changes

Check for any remote updates

Commit your work

Page 4: Version Control with Git./prs/15-441-F13/lectures/r03-version-control.pdf · Version Control with Git Ben Wasserman (benjamin@cmu.edu) 15-441 Computer Networks Recitation 3 . Carnegie

Carnegie Mellon University Computer Science Department

4/28

Options

Git

Subversion (svn)

Mercurial (hg)

Bazaar (bzr)

CVS

Dropbox

Others…

Page 5: Version Control with Git./prs/15-441-F13/lectures/r03-version-control.pdf · Version Control with Git Ben Wasserman (benjamin@cmu.edu) 15-441 Computer Networks Recitation 3 . Carnegie

Carnegie Mellon University Computer Science Department

5/28

svn

svn Repository

Usually remotely hosted, shared with a team.

Working Copy Your private universe, before commit.

svn commit svn checkout

svn update svn commit

Page 6: Version Control with Git./prs/15-441-F13/lectures/r03-version-control.pdf · Version Control with Git Ben Wasserman (benjamin@cmu.edu) 15-441 Computer Networks Recitation 3 . Carnegie

Carnegie Mellon University Computer Science Department

6/28

git

torvalds

git pull git push

jaharkes

bgilbert

wolf

abalacha

kernel@ghub

git

pull

git

pull

git

pull

git

push

git

push

git

pull

No notion of “working copy”–each is a full repository.

Page 7: Version Control with Git./prs/15-441-F13/lectures/r03-version-control.pdf · Version Control with Git Ben Wasserman (benjamin@cmu.edu) 15-441 Computer Networks Recitation 3 . Carnegie

Carnegie Mellon University Computer Science Department

7/28

Page 8: Version Control with Git./prs/15-441-F13/lectures/r03-version-control.pdf · Version Control with Git Ben Wasserman (benjamin@cmu.edu) 15-441 Computer Networks Recitation 3 . Carnegie

Carnegie Mellon University Computer Science Department

8/28

Creating a Repository (repo)

Create locally

git init .

Create remote

git init –-bare

Clone local copy

git clone git://path/to/repo

Page 9: Version Control with Git./prs/15-441-F13/lectures/r03-version-control.pdf · Version Control with Git Ben Wasserman (benjamin@cmu.edu) 15-441 Computer Networks Recitation 3 . Carnegie

Carnegie Mellon University Computer Science Department

9/28

--bare or not?

No-bare Creates a repository in your working directory

Don’t need to create multiple copies of your repo

Won’t help if you nuke the directory/disk

This is probably what you need if you’ll work in AFS

--bare

Creates a “server copy” for hosting the project

Workflow more similar to svn (but still better)

Everyone pushes to shared bare repo (like svn)

You don’t work in this copy; must clone elsewhere

You want this to develop on your PC

Page 10: Version Control with Git./prs/15-441-F13/lectures/r03-version-control.pdf · Version Control with Git Ben Wasserman (benjamin@cmu.edu) 15-441 Computer Networks Recitation 3 . Carnegie

Carnegie Mellon University Computer Science Department

10/28

Aside: network protocols

Use different protocols to pull/push to repositories.

If on the same computer: git://path/to/repo

If hosted on AFS ssh+git://path/to/repo

No ssh keys for AFS, sorry

Page 11: Version Control with Git./prs/15-441-F13/lectures/r03-version-control.pdf · Version Control with Git Ben Wasserman (benjamin@cmu.edu) 15-441 Computer Networks Recitation 3 . Carnegie

Carnegie Mellon University Computer Science Department

11/28

Aside: Configure git

git config --global user.name

“Ben Wasserman”

git config --global user.email

[email protected]

Page 12: Version Control with Git./prs/15-441-F13/lectures/r03-version-control.pdf · Version Control with Git Ben Wasserman (benjamin@cmu.edu) 15-441 Computer Networks Recitation 3 . Carnegie

Carnegie Mellon University Computer Science Department

12/28

Clone

Pull a copy of the repo to develop on

git clone git://path/to/repo

git clone ssh+git://unix.andrew.cmu.edu/afs/andrew/course/15/441-641/ANDREWID/ANDREWID-15-441-project-1.git

Page 13: Version Control with Git./prs/15-441-F13/lectures/r03-version-control.pdf · Version Control with Git Ben Wasserman (benjamin@cmu.edu) 15-441 Computer Networks Recitation 3 . Carnegie

Carnegie Mellon University Computer Science Department

13/28

status

Which files changed?

Which files aren’t being watched?

Which files are stashed for commit?

git status

Page 14: Version Control with Git./prs/15-441-F13/lectures/r03-version-control.pdf · Version Control with Git Ben Wasserman (benjamin@cmu.edu) 15-441 Computer Networks Recitation 3 . Carnegie

Carnegie Mellon University Computer Science Department

14/28

Pull

Get latest updates from remote copy

git pull

If this fails, you probably need to commit any unsaved changes

Page 15: Version Control with Git./prs/15-441-F13/lectures/r03-version-control.pdf · Version Control with Git Ben Wasserman (benjamin@cmu.edu) 15-441 Computer Networks Recitation 3 . Carnegie

Carnegie Mellon University Computer Science Department

15/28

Commit

Merge your changes into the repository

git add foo.c …

git commit

Page 16: Version Control with Git./prs/15-441-F13/lectures/r03-version-control.pdf · Version Control with Git Ben Wasserman (benjamin@cmu.edu) 15-441 Computer Networks Recitation 3 . Carnegie

Carnegie Mellon University Computer Science Department

16/28

Push

Don’t push broken code!!

git push

If this fails, you probably need to pull first

Page 17: Version Control with Git./prs/15-441-F13/lectures/r03-version-control.pdf · Version Control with Git Ben Wasserman (benjamin@cmu.edu) 15-441 Computer Networks Recitation 3 . Carnegie

Carnegie Mellon University Computer Science Department

17/28

Branch & Merge

Work on something different, without disturbing master/trunk

git branch branch_name

git checkout branch_name

do stuff…

git checkout master

git merge branch_name

Page 18: Version Control with Git./prs/15-441-F13/lectures/r03-version-control.pdf · Version Control with Git Ben Wasserman (benjamin@cmu.edu) 15-441 Computer Networks Recitation 3 . Carnegie

Carnegie Mellon University Computer Science Department

18/28

Tag

Mark a revision as “final” or “ready”

git tag tag_name

git push --tags

Page 19: Version Control with Git./prs/15-441-F13/lectures/r03-version-control.pdf · Version Control with Git Ben Wasserman (benjamin@cmu.edu) 15-441 Computer Networks Recitation 3 . Carnegie

Carnegie Mellon University Computer Science Department

19/28

Remote Hosting

github.com

bitbucket.org

svnhub.com

AFS

Google code

Sourceforge

Page 20: Version Control with Git./prs/15-441-F13/lectures/r03-version-control.pdf · Version Control with Git Ben Wasserman (benjamin@cmu.edu) 15-441 Computer Networks Recitation 3 . Carnegie

Carnegie Mellon University Computer Science Department

20/28

Aside: AFS Permissions

To make a bare repo in AFS that someone else can pull/push from:

1. Make a new directory in your home dir

2. fs sa . ANDREWID rlidwk

3. git init --bare

Page 21: Version Control with Git./prs/15-441-F13/lectures/r03-version-control.pdf · Version Control with Git Ben Wasserman (benjamin@cmu.edu) 15-441 Computer Networks Recitation 3 . Carnegie

Carnegie Mellon University Computer Science Department

21/28

Good practices

Small commits

Useful messages

Commit frequently

Develop in branches

Tag releasable versions

Page 22: Version Control with Git./prs/15-441-F13/lectures/r03-version-control.pdf · Version Control with Git Ben Wasserman (benjamin@cmu.edu) 15-441 Computer Networks Recitation 3 . Carnegie

Carnegie Mellon University Computer Science Department

22/28

Small commits

Only change one thing per commit

When something breaks, easier to trace

Page 23: Version Control with Git./prs/15-441-F13/lectures/r03-version-control.pdf · Version Control with Git Ben Wasserman (benjamin@cmu.edu) 15-441 Computer Networks Recitation 3 . Carnegie

Carnegie Mellon University Computer Science Department

23/28

Helpful commit messages

Say what you changed

Keep the first line short

Make commits easy to find

www.commitlogsfromlastnight.com

Page 24: Version Control with Git./prs/15-441-F13/lectures/r03-version-control.pdf · Version Control with Git Ben Wasserman (benjamin@cmu.edu) 15-441 Computer Networks Recitation 3 . Carnegie

Carnegie Mellon University Computer Science Department

24/28

Commit Frequently

Make changes, commit them

When something breaks, go to the commit that broke it

Only push when ready for others to get the changes Don’t make your teammates hate you

Page 25: Version Control with Git./prs/15-441-F13/lectures/r03-version-control.pdf · Version Control with Git Ben Wasserman (benjamin@cmu.edu) 15-441 Computer Networks Recitation 3 . Carnegie

Carnegie Mellon University Computer Science Department

25/28

Git questions?

Page 26: Version Control with Git./prs/15-441-F13/lectures/r03-version-control.pdf · Version Control with Git Ben Wasserman (benjamin@cmu.edu) 15-441 Computer Networks Recitation 3 . Carnegie

Carnegie Mellon University Computer Science Department

26/28

Checkpoint 2

Add basic HTTP server Read RFC 2616

Start by parsing and building HTTP headers

Serve error messages

Then HEAD requests

Then GET

Then POST

Page 27: Version Control with Git./prs/15-441-F13/lectures/r03-version-control.pdf · Version Control with Git Ben Wasserman (benjamin@cmu.edu) 15-441 Computer Networks Recitation 3 . Carnegie

Carnegie Mellon University Computer Science Department

27/28

Wireshark

Packet monitoring software

Install it. Use it.

You will want this to examine the HTTP headers you’re sending/receiving

Do the Wireshark question on HW1

Page 28: Version Control with Git./prs/15-441-F13/lectures/r03-version-control.pdf · Version Control with Git Ben Wasserman (benjamin@cmu.edu) 15-441 Computer Networks Recitation 3 . Carnegie

Carnegie Mellon University Computer Science Department

28/28

All questions?