01 - git vs svn
TRANSCRIPT
GitWhat is it and why do we need it?
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
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
Industry status - 2013
http://zeroturnaround.com/rebellabs/devprod-report-revisited-version-control-systems-in-2013/
Google Trends
http://bit.ly/rcs_trends
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
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
Model● Current state at trunk● Snapshots● Copy to different branch when
changing direction (e.g. newversion)
● Backups and CI at repository
Source
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!
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
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
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
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
Branching Model● master
o hotfix● [customer-name]● [older version]● release● develop
o feature-xyzo bugfix-tracking-number git-flow
“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
“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
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
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
SummaryWhy Git?● Industry choice● No SPOF● Branch often● Faster and easier merges● Agile-friendly model● Clarity and workflow control
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
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
Appendix - Basic Git Commands
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
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’
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
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
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
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
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
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
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
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
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
Basic Commands● git branch -D [branch name]
o delete branch● git branch -m [old name] [new name]
o rename branch