24
Version Control - A Brief Introduction to Git CS356 Object-Oriented Design and Programming http://cs356.yusun.io October 8, 2014 Yu Sun, Ph.D. http://yusun.io [email protected]

Version Control - A Brief Introduction to Gitcs356.yusun.io/slides/L05-Git.pdf · Git Basics Overview. Title: L05-Git Created Date: 10/8/2014 5:01:39 PM

  • Upload
    others

  • View
    7

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Version Control - A Brief Introduction to Gitcs356.yusun.io/slides/L05-Git.pdf · Git Basics Overview. Title: L05-Git Created Date: 10/8/2014 5:01:39 PM

Version Control - A Brief Introduction to Git

CS356 Object-Oriented Design and Programming http://cs356.yusun.io October 8, 2014 !Yu Sun, Ph.D. http://yusun.io [email protected]

Page 2: Version Control - A Brief Introduction to Gitcs356.yusun.io/slides/L05-Git.pdf · Git Basics Overview. Title: L05-Git Created Date: 10/8/2014 5:01:39 PM

Why Version Control?

Page 3: Version Control - A Brief Introduction to Gitcs356.yusun.io/slides/L05-Git.pdf · Git Basics Overview. Title: L05-Git Created Date: 10/8/2014 5:01:39 PM

Maintain Multiple Versions

• Change version

• Safe backup

Page 4: Version Control - A Brief Introduction to Gitcs356.yusun.io/slides/L05-Git.pdf · Git Basics Overview. Title: L05-Git Created Date: 10/8/2014 5:01:39 PM

Collaboration The problem to avoid

Page 5: Version Control - A Brief Introduction to Gitcs356.yusun.io/slides/L05-Git.pdf · Git Basics Overview. Title: L05-Git Created Date: 10/8/2014 5:01:39 PM

Collaboration The lock-modify-unlock solution

Page 6: Version Control - A Brief Introduction to Gitcs356.yusun.io/slides/L05-Git.pdf · Git Basics Overview. Title: L05-Git Created Date: 10/8/2014 5:01:39 PM

Collaboration The copy-modify-merge solution

Page 7: Version Control - A Brief Introduction to Gitcs356.yusun.io/slides/L05-Git.pdf · Git Basics Overview. Title: L05-Git Created Date: 10/8/2014 5:01:39 PM

Collaboration The copy-modify-merge solution

Page 8: Version Control - A Brief Introduction to Gitcs356.yusun.io/slides/L05-Git.pdf · Git Basics Overview. Title: L05-Git Created Date: 10/8/2014 5:01:39 PM

Monitor and Track Progress

Code Difference

Code Contribution

Page 9: Version Control - A Brief Introduction to Gitcs356.yusun.io/slides/L05-Git.pdf · Git Basics Overview. Title: L05-Git Created Date: 10/8/2014 5:01:39 PM

Why Git?

Page 10: Version Control - A Brief Introduction to Gitcs356.yusun.io/slides/L05-Git.pdf · Git Basics Overview. Title: L05-Git Created Date: 10/8/2014 5:01:39 PM

Why Git?

• Performance  

• Github  

• Popular

Page 11: Version Control - A Brief Introduction to Gitcs356.yusun.io/slides/L05-Git.pdf · Git Basics Overview. Title: L05-Git Created Date: 10/8/2014 5:01:39 PM

Git History

Page 12: Version Control - A Brief Introduction to Gitcs356.yusun.io/slides/L05-Git.pdf · Git Basics Overview. Title: L05-Git Created Date: 10/8/2014 5:01:39 PM
Page 13: Version Control - A Brief Introduction to Gitcs356.yusun.io/slides/L05-Git.pdf · Git Basics Overview. Title: L05-Git Created Date: 10/8/2014 5:01:39 PM

Why Command-Line?

Page 14: Version Control - A Brief Introduction to Gitcs356.yusun.io/slides/L05-Git.pdf · Git Basics Overview. Title: L05-Git Created Date: 10/8/2014 5:01:39 PM

Why Git Command-Line?

• Graphical  clients  are  based  on  CLT  

• Graphical  clients  could  cause  problems  

• Integrated  with  shell  scripts  

• Graphical  clients  not  always  available

Page 15: Version Control - A Brief Introduction to Gitcs356.yusun.io/slides/L05-Git.pdf · Git Basics Overview. Title: L05-Git Created Date: 10/8/2014 5:01:39 PM

Git Exercises

Page 16: Version Control - A Brief Introduction to Gitcs356.yusun.io/slides/L05-Git.pdf · Git Basics Overview. Title: L05-Git Created Date: 10/8/2014 5:01:39 PM

1. Create Git Repositories

• git  clone  <repo>  

• git  init  <repo>

local repository

remote repository

local repository

local repository

Page 17: Version Control - A Brief Introduction to Gitcs356.yusun.io/slides/L05-Git.pdf · Git Basics Overview. Title: L05-Git Created Date: 10/8/2014 5:01:39 PM

2. Add/Commit/Push

• git  add  <path>  

• git  commit  

• git  push

working directory

staging area

local repository

remote repository

git add

git commit

git push

localremote

Page 18: Version Control - A Brief Introduction to Gitcs356.yusun.io/slides/L05-Git.pdf · Git Basics Overview. Title: L05-Git Created Date: 10/8/2014 5:01:39 PM

3. Check Status

• git  status  

• git  log  

• git  branch

Page 19: Version Control - A Brief Introduction to Gitcs356.yusun.io/slides/L05-Git.pdf · Git Basics Overview. Title: L05-Git Created Date: 10/8/2014 5:01:39 PM

4. Sync Changes & Resolve Conflicts

• git  pull  -­‐-­‐rebase        (referred  approach)        

• git  pull  

!

• git  status  

• clean  up  conflicts  

• git  add  <conflicted  file>  

• git  rebase  -­‐-­‐continue  

• git  push

local repository

remote repository

git pull

localremote

Page 20: Version Control - A Brief Introduction to Gitcs356.yusun.io/slides/L05-Git.pdf · Git Basics Overview. Title: L05-Git Created Date: 10/8/2014 5:01:39 PM

5. Branches

• git  checkout  -­‐b  <branch>  

• git  checkout  <branch>  

• git  merge  <branch>

Feature Branch

Master

Page 21: Version Control - A Brief Introduction to Gitcs356.yusun.io/slides/L05-Git.pdf · Git Basics Overview. Title: L05-Git Created Date: 10/8/2014 5:01:39 PM

6. Git Undo

• Always  backup  first  

• Google  the  soluAon

Page 22: Version Control - A Brief Introduction to Gitcs356.yusun.io/slides/L05-Git.pdf · Git Basics Overview. Title: L05-Git Created Date: 10/8/2014 5:01:39 PM

Git Learning Resources

• http://git-scm.com/

• https://www.youtube.com/user/GitHubGuides

• Google it!

Page 23: Version Control - A Brief Introduction to Gitcs356.yusun.io/slides/L05-Git.pdf · Git Basics Overview. Title: L05-Git Created Date: 10/8/2014 5:01:39 PM

Inclass Exercises

• Checkout git-exercise project

• Complete Exercise 1, 2, 3

• Finish Assignment 2

Page 24: Version Control - A Brief Introduction to Gitcs356.yusun.io/slides/L05-Git.pdf · Git Basics Overview. Title: L05-Git Created Date: 10/8/2014 5:01:39 PM

Git Basics Overview