28
Emina Torlak [email protected] CSE 403: Software Engineering, Spring 2015 courses.cs.washington.edu/courses/cse403/15sp/ Version Control

Version Control - University of Washington · • Basic concepts behind Git • Working with Git • Creating or cloning a repository • Staging and committing changes • Pushing

  • Upload
    others

  • View
    6

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Version Control - University of Washington · • Basic concepts behind Git • Working with Git • Creating or cloning a repository • Staging and committing changes • Pushing

Emina Torlak [email protected]

CSE 403: Software Engineering, Spring 2015courses.cs.washington.edu/courses/cse403/15sp/

Version Control

Page 2: Version Control - University of Washington · • Basic concepts behind Git • Working with Git • Creating or cloning a repository • Staging and committing changes • Pushing

Outline

2

• Version control systems

• Basic concepts behind Git

• Working with Git• Creating or cloning a repository

• Staging and committing changes

• Pushing and pulling

• Branching and merging

• Hints for effective use of Git

These slides are based on http://git-scm.com/book/en/

Page 3: Version Control - University of Washington · • Basic concepts behind Git • Working with Git • Creating or cloning a repository • Staging and committing changes • Pushing

Version control systems

3

A system that records changes to a file or set of files over time so that you can recall specific versions later.

Page 4: Version Control - University of Washington · • Basic concepts behind Git • Working with Git • Creating or cloning a repository • Staging and committing changes • Pushing

Centralized version control systems

4

A single server that contains all the versioned files, and clients that check out files from that central place.

Page 5: Version Control - University of Washington · • Basic concepts behind Git • Working with Git • Creating or cloning a repository • Staging and committing changes • Pushing

Distributed version control systems

5

Clients fully mirror the repository (instead of just checking out the latest snapshot of the files).

Page 6: Version Control - University of Washington · • Basic concepts behind Git • Working with Git • Creating or cloning a repository • Staging and committing changes • Pushing

A brief history of Git

6

• Developed by Linus Torvalds for the Linux kernel in 2005

• Currently the most widely adopted version control system

• Goals• Support for non-linear development

• Fully distributed

• Efficient handling of large projects (like Linux)

Page 7: Version Control - University of Washington · • Basic concepts behind Git • Working with Git • Creating or cloning a repository • Staging and committing changes • Pushing

Version control with Git: snapshots

7

Stream of snapshots.

Page 8: Version Control - University of Washington · • Basic concepts behind Git • Working with Git • Creating or cloning a repository • Staging and committing changes • Pushing

Version control with Git: states

8

Files are committed, modified, or staged.

Page 9: Version Control - University of Washington · • Basic concepts behind Git • Working with Git • Creating or cloning a repository • Staging and committing changes • Pushing

Version control with Git: workflow

9

1. Modify files in the working directory.

2. Stage the files, adding snapshots of them to the staging area.

3. Do a commit, which takes the files as they are in the staging area and stores that snapshot permanently.

Page 10: Version Control - University of Washington · • Basic concepts behind Git • Working with Git • Creating or cloning a repository • Staging and committing changes • Pushing

• Setting up • Creating or cloning a repository• Staging and committing changes• Pushing and pulling• Branching and merging

Working with Git: basic operations

10

Page 11: Version Control - University of Washington · • Basic concepts behind Git • Working with Git • Creating or cloning a repository • Staging and committing changes • Pushing

Working with Git: first-time setup

11

$ git config --global user.name "John Doe"$ git config --global user.email [email protected]$ git config --global core.editor emacs

Set your identity and preferred editor.

Page 12: Version Control - University of Washington · • Basic concepts behind Git • Working with Git • Creating or cloning a repository • Staging and committing changes • Pushing

Working with Git: creating or cloning a repo

12

$ git init

Start tracking a project in Git.

Page 13: Version Control - University of Washington · • Basic concepts behind Git • Working with Git • Creating or cloning a repository • Staging and committing changes • Pushing

Working with Git: creating or cloning a repo

12

$ git init

Start tracking a project in Git.

$ git clone https://github.com/emina/cse403

Clone an existing repository.

Page 14: Version Control - University of Washington · • Basic concepts behind Git • Working with Git • Creating or cloning a repository • Staging and committing changes • Pushing

$ echo 'My Project' > README$ git add README$ git commit -m “readme”

Working with Git: staging and committing

13

Untracked

Page 15: Version Control - University of Washington · • Basic concepts behind Git • Working with Git • Creating or cloning a repository • Staging and committing changes • Pushing

$ echo 'My Project' > README$ git add README$ git commit -m “readme”

Working with Git: staging and committing

13

Staged

Page 16: Version Control - University of Washington · • Basic concepts behind Git • Working with Git • Creating or cloning a repository • Staging and committing changes • Pushing

$ echo 'My Project' > README$ git add README$ git commit -m “readme”

Working with Git: staging and committing

13

Unmodified

Page 17: Version Control - University of Washington · • Basic concepts behind Git • Working with Git • Creating or cloning a repository • Staging and committing changes • Pushing

Working with Git: pushing changes

14

$ git push origin master Push your master branch to your origin server.

Page 18: Version Control - University of Washington · • Basic concepts behind Git • Working with Git • Creating or cloning a repository • Staging and committing changes • Pushing

Working with Git: pushing changes

14

$ git push origin master Push your master branch to your origin server.

If out of sync with the origin, push will be rejected. Pull, merge, and try again.

Page 19: Version Control - University of Washington · • Basic concepts behind Git • Working with Git • Creating or cloning a repository • Staging and committing changes • Pushing

Working with Git: pulling changes

15

$ git pullPulls changes from the origin server and merges them into your working directory.

Page 20: Version Control - University of Washington · • Basic concepts behind Git • Working with Git • Creating or cloning a repository • Staging and committing changes • Pushing

Working with Git: pulling changes

15

$ git pullPulls changes from the origin server and merges them into your working directory.

If there are conflicting changes, merge manually, add, and commit.

Page 21: Version Control - University of Washington · • Basic concepts behind Git • Working with Git • Creating or cloning a repository • Staging and committing changes • Pushing

Working with Git: branching

16

$ git checkout -b iss53

Creates a branch and switches to it.

Page 22: Version Control - University of Washington · • Basic concepts behind Git • Working with Git • Creating or cloning a repository • Staging and committing changes • Pushing

Switch to the master branch, …

Working with Git: merging

17

$ git checkout master

Page 23: Version Control - University of Washington · • Basic concepts behind Git • Working with Git • Creating or cloning a repository • Staging and committing changes • Pushing

Switch to the master branch, and merge changes from iss53 into the master.

Working with Git: merging

18

$ git checkout master$ git merge iss53

Page 24: Version Control - University of Washington · • Basic concepts behind Git • Working with Git • Creating or cloning a repository • Staging and committing changes • Pushing

Hints for using Git: what not to commit

19

• Avoid binary files (especially simultaneous editing)• Word .doc files

• Do not commit generated files• Binaries (e.g., .class files), etc.

• Wastes space in repository

• Causes merge conflicts

Page 25: Version Control - University of Washington · • Basic concepts behind Git • Working with Git • Creating or cloning a repository • Staging and committing changes • Pushing

Hints for using Git: commit often

20

• Make many small commits, not one big one• Easier to understand, review, merge, revert

• How to make many small commits:• Do only one task at a time and commit after each one

• Create a new clone for each simultaneous task

• Create a branch for each simultaneous task

• Somewhat more efficient

• Somewhat more complicated and error-prone

• Easier to share unfinished work with teammates

Page 26: Version Control - University of Washington · • Basic concepts behind Git • Working with Git • Creating or cloning a repository • Staging and committing changes • Pushing

Hints for using Git: synchronize often

21

• Pull often• Avoid getting behind the master or your teammates

• Push as often as practical• Don’t destabilize the master build

• Automatic testing on each push is a good idea

Page 27: Version Control - University of Washington · • Basic concepts behind Git • Working with Git • Creating or cloning a repository • Staging and committing changes • Pushing

Hints for using Git: avoid merge conflicts

22

• Modularize your work• Divide work so that individuals or subteams “own” a module

• Other team members only need to understand its specification

• Requires good documentation and testing

• Communicate about changes that may conflict• But don’t overwhelm the team in such messages

Page 28: Version Control - University of Washington · • Basic concepts behind Git • Working with Git • Creating or cloning a repository • Staging and committing changes • Pushing

Summary

23

• Version control systems record changes to a file or set of files over time so that you can recall specific versions later.

• Git is the recommended VCS for 403.

• Learn more at http://git-scm.com/book/en/