01 - git vs svn
TRANSCRIPT
![Page 1: 01 - Git vs SVN](https://reader033.vdocuments.net/reader033/viewer/2022042514/55cbab72bb61ebd2088b45dd/html5/thumbnails/1.jpg)
GitWhat is it and why do we need it?
![Page 2: 01 - Git vs SVN](https://reader033.vdocuments.net/reader033/viewer/2022042514/55cbab72bb61ebd2088b45dd/html5/thumbnails/2.jpg)
Revision Control Systems● Automation of storing, retrieval, logging,
identification, and merging of revisions● Current state + history of changes● Mainly source code tracking - but also
binaries● Usually has CLI, but we prefer GUI and IDE
integration for ease and clarity
![Page 3: 01 - Git vs SVN](https://reader033.vdocuments.net/reader033/viewer/2022042514/55cbab72bb61ebd2088b45dd/html5/thumbnails/3.jpg)
Centralized vs Distributed● Client-Server● Central repository● Store changes
locally● Slow access to
non-local● SVN, CVS
● Peer-to-peer● Each user forks the
entire repository● Fast performance● “Actual” state
issues● Git, Mercurial
![Page 4: 01 - Git vs SVN](https://reader033.vdocuments.net/reader033/viewer/2022042514/55cbab72bb61ebd2088b45dd/html5/thumbnails/4.jpg)
Industry status - 2013
http://zeroturnaround.com/rebellabs/devprod-report-revisited-version-control-systems-in-2013/
![Page 5: 01 - Git vs SVN](https://reader033.vdocuments.net/reader033/viewer/2022042514/55cbab72bb61ebd2088b45dd/html5/thumbnails/5.jpg)
Google Trends
http://bit.ly/rcs_trends
![Page 6: 01 - Git vs SVN](https://reader033.vdocuments.net/reader033/viewer/2022042514/55cbab72bb61ebd2088b45dd/html5/thumbnails/6.jpg)
SVN● Apache Subversion● Centralized version control system (CVCS)● Created 2000 as CVS replacement, top-level
Apache - project 2010● Widely used across the industry● Mature system● Good GUI tools
Wikipedia
![Page 7: 01 - Git vs SVN](https://reader033.vdocuments.net/reader033/viewer/2022042514/55cbab72bb61ebd2088b45dd/html5/thumbnails/7.jpg)
Basic Concepts● Repository - central server● Trunk - current state● Tag - named snapshot● Branch - development fork● Working copy - private workplace● Commit - push local changes to server● Update - update local with server changes
![Page 8: 01 - Git vs SVN](https://reader033.vdocuments.net/reader033/viewer/2022042514/55cbab72bb61ebd2088b45dd/html5/thumbnails/8.jpg)
Model● Current state at trunk● Snapshots● Copy to different branch when
changing direction (e.g. newversion)
● Backups and CI at repository
Source
![Page 9: 01 - Git vs SVN](https://reader033.vdocuments.net/reader033/viewer/2022042514/55cbab72bb61ebd2088b45dd/html5/thumbnails/9.jpg)
Workflow1. Checkout from trunk to working directory2. Develop feature / fix bug3. Update working directory4. Merge conflicts5. Commit changes to server6. Go to 2Note: one branch usually - costly merges!
![Page 10: 01 - Git vs SVN](https://reader033.vdocuments.net/reader033/viewer/2022042514/55cbab72bb61ebd2088b45dd/html5/thumbnails/10.jpg)
Git● Distributed version control system (DVCS)● Created 2005 by Linus Torvalds for Linux
kernel development● Embraced by FOSS - and by industry● Independent of network state● Fast due to locality● Smaller sized directories
Wikipedia
![Page 11: 01 - Git vs SVN](https://reader033.vdocuments.net/reader033/viewer/2022042514/55cbab72bb61ebd2088b45dd/html5/thumbnails/11.jpg)
Basic Concepts● Local repository - local copy (fork)● Staging area - files to be committed next● Working directory - files changes made to● Commit - copy changes from staging area to
local repository● Branch - a separate line of development● Clone - mirror an entire repository
![Page 12: 01 - Git vs SVN](https://reader033.vdocuments.net/reader033/viewer/2022042514/55cbab72bb61ebd2088b45dd/html5/thumbnails/12.jpg)
Basic Concepts● Tag - immutable name for a commit● Pull - update local repo from remote repo● Push - update remote repo with local repo● HEAD - pointer to latest commit● Revision - version of code, represented by
commits and identified by SHA1 hash● URL - the repo’s location
![Page 13: 01 - Git vs SVN](https://reader033.vdocuments.net/reader033/viewer/2022042514/55cbab72bb61ebd2088b45dd/html5/thumbnails/13.jpg)
Basic Concepts● Stash - a “stack” style cache of changes
o used to save temp progress when changing branch● master - main branch of the repository● origin - pointer to origin of master, by
convention● remote - pointer to remote repository
o usually - the upstream
![Page 15: 01 - Git vs SVN](https://reader033.vdocuments.net/reader033/viewer/2022042514/55cbab72bb61ebd2088b45dd/html5/thumbnails/15.jpg)
Branching Model● master
o hotfix● [customer-name]● [older version]● release● develop
o feature-xyzo bugfix-tracking-number git-flow
![Page 16: 01 - Git vs SVN](https://reader033.vdocuments.net/reader033/viewer/2022042514/55cbab72bb61ebd2088b45dd/html5/thumbnails/16.jpg)
“Squash” Workflow1. Pull to update your local master2. Check out a feature branch3. Do work in your feature branch, committing
early and often4. Rebase frequently to incorporate upstream
changes5. Interactive rebase (squash) your commits
![Page 17: 01 - Git vs SVN](https://reader033.vdocuments.net/reader033/viewer/2022042514/55cbab72bb61ebd2088b45dd/html5/thumbnails/17.jpg)
“Squash” Workflow6. Merge your changes with master7. Push your changes to the upstream8. Delete unnecessary leftovers
http://reinh.com/blog/2009/03/02/a-git-workflow-for-agile-teams.html
![Page 18: 01 - Git vs SVN](https://reader033.vdocuments.net/reader033/viewer/2022042514/55cbab72bb61ebd2088b45dd/html5/thumbnails/18.jpg)
Deliverables● master -> CI -> STABLE -> production
o “final”● hotfix -> CI -> STABLE -> production● release -> CI -> RC -> production/staging
o “beta”● develop -> CI -> NIGHTLY -> staging
o “alpha”● feature / fix / bugfix / local -> testing
![Page 19: 01 - Git vs SVN](https://reader033.vdocuments.net/reader033/viewer/2022042514/55cbab72bb61ebd2088b45dd/html5/thumbnails/19.jpg)
Important● Master + release [+ customer] - deployable!● Branch per feature and per bug● Branch often - commit and merge even more● Remote - for tracking, local - for
experimenting● Descriptive naming
![Page 20: 01 - Git vs SVN](https://reader033.vdocuments.net/reader033/viewer/2022042514/55cbab72bb61ebd2088b45dd/html5/thumbnails/20.jpg)
SummaryWhy Git?● Industry choice● No SPOF● Branch often● Faster and easier merges● Agile-friendly model● Clarity and workflow control
![Page 21: 01 - Git vs SVN](https://reader033.vdocuments.net/reader033/viewer/2022042514/55cbab72bb61ebd2088b45dd/html5/thumbnails/21.jpg)
Further reading● http://nvie.com/posts/a-successful-git-branch
ing-model/● http://scottchacon.com/2011/08/31/github-flo
w.html● http://x-team.com/2013/09/our-git-workflow-f
orks-with-feature-branches/● http://www.tutorialspoint.com/git/index.htm
![Page 22: 01 - Git vs SVN](https://reader033.vdocuments.net/reader033/viewer/2022042514/55cbab72bb61ebd2088b45dd/html5/thumbnails/22.jpg)
Further reading● http://git-scm.com/book/en/v2● https://www.jetbrains.com/idea/help/using-git-int
egration.html● https://git.wiki.kernel.org/index.php/GitSvnComp
arsion● https://www.atlassian.com/git/● http://www.toptal.com/git/git-workflows-for-pros-
a-good-git-guide
![Page 23: 01 - Git vs SVN](https://reader033.vdocuments.net/reader033/viewer/2022042514/55cbab72bb61ebd2088b45dd/html5/thumbnails/23.jpg)
Appendix - Basic Git Commands
![Page 24: 01 - Git vs SVN](https://reader033.vdocuments.net/reader033/viewer/2022042514/55cbab72bb61ebd2088b45dd/html5/thumbnails/24.jpg)
Basic Commands● git --version
o version of locally installed git server● git --bare init
o create local repository without working directoryo useful for “server” repository
● git inito creates local repository with a working directory
![Page 25: 01 - Git vs SVN](https://reader033.vdocuments.net/reader033/viewer/2022042514/55cbab72bb61ebd2088b45dd/html5/thumbnails/25.jpg)
Basic Commands● git status -s
o show current status of staging area● git add .
o add all changed files to staging area● git add [filename]
o add specific file to changing area● git commit -m ‘Message’
o commit files in staging area with message ‘Message’
![Page 26: 01 - Git vs SVN](https://reader033.vdocuments.net/reader033/viewer/2022042514/55cbab72bb61ebd2088b45dd/html5/thumbnails/26.jpg)
Basic Commands● git remote add [branch name] [URL]
o specify branch name at URL as our remoteo branch can be origin
● git push [branch-name1] [branch-name2]o push changes from branch2 to branch1o can be remote, origin, master, etc
● git clone [URL]o clone URL to current directory as a local repository
![Page 27: 01 - Git vs SVN](https://reader033.vdocuments.net/reader033/viewer/2022042514/55cbab72bb61ebd2088b45dd/html5/thumbnails/27.jpg)
Basic Commands● git log
o show the commit log● git show [SHA1]
o show details and diff of specific commit● git commit --amend -m ‘Message’
o fix last commit● git diff
o show the diff from last commit
![Page 28: 01 - Git vs SVN](https://reader033.vdocuments.net/reader033/viewer/2022042514/55cbab72bb61ebd2088b45dd/html5/thumbnails/28.jpg)
Basic Commands● git pull
o sync local repository with remote● git stash
o save current changes before switching to a different branch
o not a commit● git stash list
o see current stashes
![Page 29: 01 - Git vs SVN](https://reader033.vdocuments.net/reader033/viewer/2022042514/55cbab72bb61ebd2088b45dd/html5/thumbnails/29.jpg)
Basic Commands● git stash pop
o go back to stashed state● git mv [filename] [directory]
o move file to a different directoryo can be used to rename files
● git add [filename]o create and add a file
![Page 30: 01 - Git vs SVN](https://reader033.vdocuments.net/reader033/viewer/2022042514/55cbab72bb61ebd2088b45dd/html5/thumbnails/30.jpg)
Basic Commands● git rm [filename]
o remove file● git checkout [filename]
o get the committed version of fileo also used to reset or undelete file
![Page 31: 01 - Git vs SVN](https://reader033.vdocuments.net/reader033/viewer/2022042514/55cbab72bb61ebd2088b45dd/html5/thumbnails/31.jpg)
Basic Commands● gir reset [option] [pointer]
o move HEAD to pointero effectively move back in historyo HEAD~ = one backo --soft - don’t delete “future” commitso --mixed - remove uncommitted changes from
staging default option
o --hard - delete “future” commits + staging
![Page 32: 01 - Git vs SVN](https://reader033.vdocuments.net/reader033/viewer/2022042514/55cbab72bb61ebd2088b45dd/html5/thumbnails/32.jpg)
Basic Commands● git tag -a ‘Name’ -m ‘Message’
o tag current HEAD, i.e. last commit● git tag -1
o view tags● git tag -d ‘Name’
o delete tag from local and from remote
![Page 33: 01 - Git vs SVN](https://reader033.vdocuments.net/reader033/viewer/2022042514/55cbab72bb61ebd2088b45dd/html5/thumbnails/33.jpg)
Basic Commands● git format-patch -1
o create patch files for the commit● git apply [patch name]
o applies patch without creating commit● git am [patch name]
o applies patch and creates commit
![Page 34: 01 - Git vs SVN](https://reader033.vdocuments.net/reader033/viewer/2022042514/55cbab72bb61ebd2088b45dd/html5/thumbnails/34.jpg)
Basic Commands● git branch
o see existing branches● git branch [branch name]
o create a new branch pointing an current HEAD● git checkout [branch name]
o switch to a different branch● git checkout -b [branch name]
o create new branch at HEAD and switch to it
![Page 35: 01 - Git vs SVN](https://reader033.vdocuments.net/reader033/viewer/2022042514/55cbab72bb61ebd2088b45dd/html5/thumbnails/35.jpg)
Basic Commands● git branch -D [branch name]
o delete branch● git branch -m [old name] [new name]
o rename branch