Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS5220 Advanced Topics in Web Programming Version Control with Git

Similar presentations


Presentation on theme: "CS5220 Advanced Topics in Web Programming Version Control with Git"— Presentation transcript:

1 CS5220 Advanced Topics in Web Programming Version Control with Git
Chengyu Sun California State University, Los Angeles

2 Roadmap Basic version control concepts and operations
Tag, branch, merge, and rebase Remote repositories and collaboration

3 The Process of Application Development
Initial coding Prototype Add more features Release Version 1.0 New feature development and bug fixes Release Version 2.0

4 Problems During Development
Initial coding Prototype Add more features New feature has broken existing code. Release Version 1.0 How do we find out which part of the code has been changed? How do we revert back to the previous version? New feature development and bug fixes Release Version 2.0

5 Problems During Development
Initial coding Prototype Add more features Can we give the customer the development version with the bug fix? Do we still have the Version 1.0 code? Release Version 1.0 New feature development and bug fixes Customer 1 requests a feature or bug fix. Release Version 2.0

6 Problems During Development
Initial coding Prototype Where do we put in the bug fix? Version 1.0 Version customer 1’s feature / bug fix Development version Add more features Release Version 1.0 New feature development and bug fixes Customer 2 requests a feature or bug fix. Release Version 2.0

7 Problems During Development
Initial coding Prototype Add more features Release Version 1.0 How many different versions do we need to maintain? New feature development and bug fixes Customer n requests a feature or bug fix. Release Version 2.0

8 Problems During Development
Initial coding Prototype Add more features How do we collect all the bug fixes into one release? Release Version 1.0 Put all changes into an intermediate release. New feature development and bug fixes Release Version 2.0 Release Version 1.1

9 Version Control Systems
CVS Used to be the most popular / well known / widely used open source version control system Obsolete due to some inherent system limitations Open Source Git, Subversion, … Commercial Team Foundation Server, ClearCase, …

10 Why Git? Popularity GitHub

11 A Little History … 1991 – Linus Torvalds started the development of Linux 2001 – Linux Kernel 2.5 Release More than 3 million lines of code Hundreds of developers from all over the world Individual use of version control (mostly CVS)

12 … A Little History 2002 – BitKeeper adopted as the version control system for Linux kernel Good system for large, distributed software development Proprietary software and restrictive license terms 2005 End of the use of BitKeeper for Linux kernel development Linus Torvalds created Git (there is no going back to CVS!)

13 Using Git Command line: git
GUI: IDE integration in Eclipse, IntelliJ IDEA, Android Studio, Visual Studio …

14 Version Control A Project
Unmanaged Copy Repository /project file1 file2 /project file1 file2 /project file1 file2 /project file1 file2 Working Copy /project /special folder used by VCS file1 file2 Versions (Revisions)

15 Git Init Run git init in the project folder
Creates a repository for the project (under /.git) Makes the current project folder a working copy (also using /.git) No files are under version control yet

16 Share Project in Eclipse
Right click on the project and select Team  Share Project … Performs git init for an unmanaged project, or Makes Eclipse aware of the repository for a project that’s already under version control

17 What Files Should Be Under Version Control?
The minimal set of files that needed to build the project Examples Build file, e.g. pom.xml?? Source code, e.g. java files?? Generated files, e.g. class files?? Graphic assets, e.g. images and icons?? Libraries, e.g. jar files?? Eclipse project files: .project, .classpath, .settings

18 The Files That Should Not Be Under Version Control
.gitignore /target/ /test-output/ /.project /.classpath /.settings/ See for more gitignore patterns.

19 Commit – Save Changes to Repository
/project file1 file2 Working Copy /project file1 file2 /project file1 file2 /project file1 file2 [Modified] file3 [Added] …. commit Versions (Revisions)

20 The Git Index A.K.A. The staging area or cache
Technically Git only commits files added to the index (i.e. staged) Command line option and GUI can simplified this intermediate step Working Copy Index Repository /project file1 file2 [Modified] file3 [Added] …. file2 [Modified] file3 [Added] add commit

21 A Few Common Version Control Operations
status: check which files are added/modified diff: see the changes revert: undo the changes log: see the commit

22 Roadmap Basic version control concepts and operations
Tag, branch, merge, and rebase Remote repositories and collaboration

23 Recall an Earlier Version of a Project
Repository In any VCS, it’s always possible to recall an earlier version of a project In Git, each commit has an unique ID, which is the SHA-1 hash of the repository after the commit 1c96400 6da4b3a The version after commit

24 Tag – Give Some Versions More Memorable Names
Repository 1c96400 Tag “version-1.0” git tag –a version-1.0 –m “Tag version 1.0” Annotated tags for very important versions, e.g. releases Lightweight tags for somewhat important versions, e.g. used as reminders for yourself

25 Branch – Work in Parallel
version-1.0 c1 c2 c3 c4 master c5 c6 v1-c1-branch Create a branch based on version 1.0 to added the feature requested by Customer #1

26 Merge – Copy Changes Between Branches
git merge <branch> Copy the changes from <branch> to the current branch

27 Fast-Forward Merge … master c1 c2 c3 Created branchA c4 c5 branchA

28 … Fast-Forward Merge git merge branchA c1 c2 c3 master c4 c5 branchA

29 Three-Way Merge … master c5 c1 c2 c3 c4 git merge branchA branchA
“Hello World” c1 c2 c3 c4 “Hello CS5220” git merge branchA Should we keep “Hello World” or “Hello CS5220” after the merge?? branchA

30 … Three-Way Merge master c5 c1 c2 c3 c4 git merge branchA branchA
“Hello CS5220” c5 “Hello World” c1 c2 c3 c4 “Hello CS5220” git merge branchA Should we keep “Hello World” or “Hello CS5220” after the merge?? branchA

31 Merge Conflict master c5 c1 c2 c3 c4 branchA “Goodbye” “Hello World”
“Hello CS5220” branchA

32 Manually Resolve Merge Conflict
Manually edit the file Add the edited file to Git index to indicate the conflict is resolved

33 After Merge master c5 c6 c1 c2 c3 c4 branchA c6 is called a
“merge commit’ c4 branchA

34 Rebase … master c5 c6 c1 c2 c3 branchA c4

35 … Rebase Takes the changes made in c4 and apply them to c5 to create c6 Rewrite history to make it looks like branchA started from c5 instead of c3

36 About Rebase c6 has the same content whether it’s from a merge or a rebase Rebase makes for a cleaner history Think of rebase as a merged performed by the person in charge of branchA instead of the person in charge of master There are some other trickier usage of rebase because of its ability to rewrite history

37 Roadmap Basic version control concepts and operations
Tag, branch, merge, and rebase Remote repositories and collaboration

38 Centralized VCS vs. Git Centralized VCS Git ?? Repository Repository
Working Copy Working Copy Repository ?? Working Copy Working Copy Working Copy

39 Git Remote Setup (I) Remote Repository
Local Repository Local Repository Local Repository Working Copy Working Copy Working Copy Working copy does not interact with remote repository directly.

40 Git Remote Setup (II) Remote Repository Remote Repository Remote
Local Repository Local Repository Local Repository Working Copy Working Copy Working Copy A local repository can interact with many remote repositories.

41 Create A Remote Repository
Create a remote repository on GitHub Push the local repository to GitHub git remote add origin <url> Add a remote repository called “origin” at the <url> git push -u origin master Push the local master branch to the master branch in the remote repository called origin Set up the local master branch as a tracking branch of the remote branch origin/master

42 Understand Push – In The Beginning
Local Repository Remote Repository c1 c1 c2 c2 master origin/master master

43 Understand Push – After A Local Commit
Local Repository Remote Repository c1 c1 c2 c2 origin/master master c3 master

44 Understand Push – After Push
Local Repository Remote Repository c1 c1 c2 c2 c3 c3 master origin/master master A “tracking branch” simply tells Git which branch the changes should be pushed to (or fetch/pull from).

45 Fetch – Somebody Else Pushed A Commit to Remote
Local Repository Remote Repository c1 c1 c2 c2 c3 c3 master origin/master c4 master

46 Fetch – After Fetch Local Repository Remote Repository c1 c1 c2 c2 c3
master c4 c4 origin/master master

47 Pull = Fetch + Merge Local Repository Remote Repository c1 c1 c2 c2 c3
master origin/master master

48 Git Clone Create a local repository from a remote repository
Git Clone in Eclipse Use Git Perspective The default repository location is under $USER/git (i.e. outside Eclipse workspace) Need to perform a project import after the repository is created

49 GitHub Fork Somebody else’s Account Your Account Fork GitHub
Repository Repository Clone Local Repository

50 Collaboration Models Different ways a team of developers collaborate on a project Centralized De-centralized

51 Developer (Team Leader)
Centralized Model Remote Repository Local Repository Local Repository Local Repository Working Copy Working Copy Working Copy Developer Developer (Team Leader) Developer

52 About Centralized Model …
Each developer work on their own branches A team leader is in charge of the important branches (e.g. master) Changes can be copied between branches using merge/rebase Similar to using a centralized VCS

53 … About Centralized Model
All developers need write access to the same repository Repository “collaborators” on GitHub

54 Developer (Team Leader)
De-Centralized Model GitHub Pull Requests Official Repository Remote Repository Remote Repository Local Repository Local Repository Local Repository Working Copy Working Copy Working Copy Developer (Team Leader) Developer Developer

55 About De-Centralized Model
Each developer work with their own remote repository A team leader maintains the “official” project repository Changes can be exchanged using Git remote operations or GitHub Pull Requests The more “git way” of collaboration

56 GitHub Pull Request … A request made by developer A to developer B
Requesting some changes made by A to be merged into B’s repository Include two branches and some description of the changes A branch in A’s repository (where the changes are) A branch in B’s repository (where the changes will be merged to)

57 … GitHub Pull Request GitHub support for pull requests
notifications Detection of merge conflicts Easy-to-use web UI for non-conflict merges Instructions for merges with conflicts

58 Readings Pro Git -


Download ppt "CS5220 Advanced Topics in Web Programming Version Control with Git"

Similar presentations


Ads by Google