KEMBAR78
01 - Git vs SVN | PPTX
Git
What 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. new
version)
● Backups and CI at repository
Source
Workflow
1. Checkout from trunk to working directory
2. Develop feature / fix bug
3. Update working directory
4. Merge conflicts
5. Commit changes to server
6. Go to 2
Note: 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
Basic Workflow
Source
Branching Model
● master
o hotfix
● [customer-name]
● [older version]
● release
● develop
o feature-xyz
o bugfix-tracking-number git-flow
“Squash” Workflow
1. Pull to update your local master
2. Check out a feature branch
3. Do work in your feature branch, committing
early and often
4. Rebase frequently to incorporate upstream
changes
5. Interactive rebase (squash) your commits
“Squash” Workflow
6. Merge your changes with master
7. Push your changes to the upstream
8. 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
Summary
Why 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-
branching-model/
● http://scottchacon.com/2011/08/31/github-
flow.html
● http://x-team.com/2013/09/our-git-workflow-
forks-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-
integration.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 directory
o useful for “server” repository
● git init
o 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 remote
o branch can be origin
● git push [branch-name1] [branch-name2]
o push changes from branch2 to branch1
o 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 directory
o 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 file
o also used to reset or undelete file
Basic Commands
● gir reset [option] [pointer]
o move HEAD to pointer
o effectively move back in history
o HEAD~ = one back
o --soft - don’t delete “future” commits
o --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

01 - Git vs SVN

  • 1.
    Git What is itand why do we need it?
  • 2.
    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
  • 3.
    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
  • 4.
    Industry status -2013 http://zeroturnaround.com/rebellabs/devprod-report-revisited-version-control-systems-in-2013/
  • 5.
  • 6.
    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
  • 7.
    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
  • 8.
    Model ● Current stateat trunk ● Snapshots ● Copy to different branch when changing direction (e.g. new version) ● Backups and CI at repository Source
  • 9.
    Workflow 1. Checkout fromtrunk to working directory 2. Develop feature / fix bug 3. Update working directory 4. Merge conflicts 5. Commit changes to server 6. Go to 2 Note: one branch usually - costly merges!
  • 10.
    Git ● Distributed versioncontrol 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
  • 11.
    Basic Concepts ● Localrepository - 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
  • 12.
    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
  • 13.
    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
  • 14.
  • 15.
    Branching Model ● master ohotfix ● [customer-name] ● [older version] ● release ● develop o feature-xyz o bugfix-tracking-number git-flow
  • 16.
    “Squash” Workflow 1. Pullto update your local master 2. Check out a feature branch 3. Do work in your feature branch, committing early and often 4. Rebase frequently to incorporate upstream changes 5. Interactive rebase (squash) your commits
  • 17.
    “Squash” Workflow 6. Mergeyour changes with master 7. Push your changes to the upstream 8. Delete unnecessary leftovers http://reinh.com/blog/2009/03/02/a-git-workflow- for-agile-teams.html
  • 18.
    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
  • 19.
    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
  • 20.
    Summary Why Git? ● Industrychoice ● No SPOF ● Branch often ● Faster and easier merges ● Agile-friendly model ● Clarity and workflow control
  • 21.
    Further reading ● http://nvie.com/posts/a-successful-git- branching-model/ ●http://scottchacon.com/2011/08/31/github- flow.html ● http://x-team.com/2013/09/our-git-workflow- forks-with-feature-branches/ ● http://www.tutorialspoint.com/git/index.htm
  • 22.
    Further reading ● http://git-scm.com/book/en/v2 ●https://www.jetbrains.com/idea/help/using-git- integration.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
  • 23.
    Appendix - BasicGit Commands
  • 24.
    Basic Commands ● git--version o version of locally installed git server ● git --bare init o create local repository without working directory o useful for “server” repository ● git init o creates local repository with a working directory
  • 25.
    Basic Commands ● gitstatus -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’
  • 26.
    Basic Commands ● gitremote add [branch name] [URL] o specify branch name at URL as our remote o branch can be origin ● git push [branch-name1] [branch-name2] o push changes from branch2 to branch1 o can be remote, origin, master, etc ● git clone [URL] o clone URL to current directory as a local repository
  • 27.
    Basic Commands ● gitlog 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
  • 28.
    Basic Commands ● gitpull 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
  • 29.
    Basic Commands ● gitstash pop o go back to stashed state ● git mv [filename] [directory] o move file to a different directory o can be used to rename files ● git add [filename] o create and add a file
  • 30.
    Basic Commands ● gitrm [filename] o remove file ● git checkout [filename] o get the committed version of file o also used to reset or undelete file
  • 31.
    Basic Commands ● girreset [option] [pointer] o move HEAD to pointer o effectively move back in history o HEAD~ = one back o --soft - don’t delete “future” commits o --mixed - remove uncommitted changes from staging  default option o --hard - delete “future” commits + staging
  • 32.
    Basic Commands ● gittag -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
  • 33.
    Basic Commands ● gitformat-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
  • 34.
    Basic Commands ● gitbranch 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
  • 35.
    Basic Commands ● gitbranch -D [branch name] o delete branch ● git branch -m [old name] [new name] o rename branch