From SVN toGit<br />with a pinchofGitHub<br />Marco De Stefano<br />
SVN features<br />Centralizedversioncontrol<br />Commitasatomicoperation<br />Versioningmantainedfordirectories and file m...
.svndirectories in the whole project
Lackof management tools (e.g. deleting part of the history)</li></li></ul><li>SVN commands<br />>svn checkout (co)<br />>s...
Centralized vs. Distributedversioncontrol<br />“Centralized VCS systems are designedwith the intentthatthereisOneTrue Sour...
Centralized vs. Distributedversioncontrol<br />
Centralized vs. Distributedversioncontrol<br />
Gitfeatures<br />Distributedversioncontrol<br />Strong supportfornon-lineardevelopment (branches and merges)<br />Efficien...
Not for Windows  (but there is a native porting, msysgit)</li></li></ul><li>Gitcommands<br />>gitinit<br />Creates a .git...
Gitcommands<br />>git clone <url> [path]<br />Copies a project in yourworking directory<br />Itcopiesall the project histo...
Gitcommands<br />>gitadd [filepattern…]<br />Adds file contentstoyourstaging area<br />Usedfornewfiles and modificationsto...
Gitcommands<br />>git status [-s]<br />Shows the status of the files (working directory and staging area)<br />Givescontex...
Gitcommands<br />>gitdiff [--cached / HEAD] [--stat] [filepath]<br />Shows a patch ofcontentchangedsince last commit and n...
Gitcommands<br />>gitcommit [-a] [-m ‘commitmessage’]<br />Records a snapshotof the staging area in the currentbranch<br /...
Gitcommands<br />>git reset [--hard] <HEAD/commit> [--files…]<br />Unstageschangesthathavebeenstaged<br />With --hard opti...
Gitcommands<br />>gitrm [--cached] [files…]<br />Removesfilesfrom the staging area – and from the working directory<br />-...
Gitcommands<br />>gitmv <source> <destination><br />Has the samebehaviourof:<br />>gitrm--cached <source><br />>mv <source...
Gitcommands<br />>gitbranch [-d <branchname>] [branchname]<br />A branchis a contextwhereyou can switch<br />Withoutargume...
Gitcommands<br />>git checkout [[-b] <branchname>]/ [--files…]<br />Swithcestobranchname<br />-boptionwill create branchna...
Gitcommands<br />>gitmerge <branchname><br />Merges the diffsbetween the currentbranch and branchnameinto the currentone<b...
Gitcommands<br />>git log [--oneline] [--graph] [--decorate] [branchname]<br />Showscommithistoryofbranchname(the currento...
Gitcommands<br />>git remote [-v] [add <url> <alias>]/[rm <alias>]<br />Lists the remote repositoryaliasesstored, -voption...
Gitcommands<br />>gitfetch <alias/--all><br />Downloadsbranches and data from a remote repository<br />--alloptionallowsto...
Gitcommands<br />>git pull <alias>/<--all><br />Fetchesfrom a remote repository and triestomergeitinto the currentbranch<b...
Gitcommands<br />>gitpush <alias> [branch]<br />Pusheslocalbranches and data to a remote repository<br />If no branchisspe...
Gitcommands<br />>gitrevert [-n] <HEAD/commit><br />Reverts the contentsof the currentbranchto the commitstate<br />Itmake...
Gitcommands<br />>gitstash <save/pop><br />Allowsto record the current state of the working directory<br />Doesn’tmake a c...
Tips<br />Enable console colors<br />>gitconfig --global color.diff auto<br />>gitconfig --global color.status auto<br />>...
GitHub<br />Web-based hosting service for software developmentprojectsthatuseGit<br />Possibletohave public repositories (...
GitHub– Create a repo<br />
GitHub– Create a repo<br />>mkdirhelp-example<br />>cd help-example<br />>gitinit<br />>touch README<br />>gitcommit -a –m...
GitHub–Push data<br />I can’tpush, “Permissiondenied (public key)”<br />Topush data, youhaveto set up a pairof SSH keys, a...
A simple scenario<br />Alice createdherrepo, test, on github (seepreviousslides), containingthesefiles:<br />README foo.tx...
A simple scenario<br />Bob modifiesfoo.txt and bar.txt; afterthatheruns:<br />>gitaddfoo.txt<br />>git status –s<br />Mbar...
A simple scenario<br />Bob wantstomodifytest.c in a newbranch, withouthaving the *.txtfilesmodified<br />>git checkout mas...
A simple scenario<br />Meanwhile, Alice modifies README and test.c, and runs:<br />>gitcommit–a–m ‘modifiedreadme and test...
A simple scenario<br />Bob triestopush the changesinto the origin<br />>git checkout master<br />>gitmergesrc-changes<br /...
A simple scenario<br />Gittriestomergecontents– and it’sverylikelytobeableto do it<br />IfGit can’tmergecorrectly, Bob wil...
Upcoming SlideShare
Loading in …5
×

SVN 2 Git

15,897 views

Published on

A small presentation for developers with good SVN knowledge that are going to working with Git.
The presentation also contains an example of repository creation on github and a simple scenario of collaboration between two developers

Published in: Technology

SVN 2 Git

  1. 1. From SVN toGit<br />with a pinchofGitHub<br />Marco De Stefano<br />
  2. 2. SVN features<br />Centralizedversioncontrol<br />Commitasatomicoperation<br />Versioningmantainedfordirectories and file metadata<br />Client/Server protocolsendsdiffs<br /><ul><li>Renamingoffilescauses loss of the history
  3. 3. .svndirectories in the whole project
  4. 4. Lackof management tools (e.g. deleting part of the history)</li></li></ul><li>SVN commands<br />>svn checkout (co)<br />>svncommit (ci)<br />>svn status (st)<br />>svn update<br />>svnrevert<br />>svnadd/rm<br />>svnadmin create<br />…<br />
  5. 5. Centralized vs. Distributedversioncontrol<br />“Centralized VCS systems are designedwith the intentthatthereisOneTrue Source thatisBlessed, and thereforeGood. Alldevelopers work (checkout) fromthat source, and thenadd (commit) theirchanges, whichthenbecomesimilarlyBlessed.”<br />“Distributed VCS systems are designedwith the intentthatonerepositoryisasgoodasanyother, and thatmergesfromonerepositorytoanother are just anotherformofcommunication. Anysemanticvalueastowhichrepositoryshouldbetrustedisimposedfrom the outsidebyprocess, notby the software itself.”<br />“The realchoicebetweenusingonetype or the otherisorganizational - ifyour project or organizationwantscentralizedcontrol, then a DVCS is a non-starter. Ifyourdevelopers are expectedto work allover the country/world, withoutsecure broadband connectionsto a centralrepository, then DVCS isprobablyyoursalvation. Ifyouneedboth, you're fu***d.”<br />
  6. 6. Centralized vs. Distributedversioncontrol<br />
  7. 7. Centralized vs. Distributedversioncontrol<br />
  8. 8. Gitfeatures<br />Distributedversioncontrol<br />Strong supportfornon-lineardevelopment (branches and merges)<br />Efficienthandlingoflargeprojects (e.g. Linux Kernel)<br />Pluggablemergestrategies<br />.git directory in project root<br /><ul><li>More disk spacerequired
  9. 9. Not for Windows  (but there is a native porting, msysgit)</li></li></ul><li>Gitcommands<br />>gitinit<br />Creates a .gitsubdirectory in your project<br />Yourworking directory becomes a gitrepository<br />Youusegitinittomakeanexisting directory ofcontentinto a newGitrepository. You can do this in any directory at anytime, completelylocally<br />
  10. 10. Gitcommands<br />>git clone <url> [path]<br />Copies a project in yourworking directory<br />Itcopiesall the project historylocally<br />Youwillget a directory with the mainbranchof the project<br />Youusegit clone toget a local copy of a Gitrepository<br />
  11. 11. Gitcommands<br />>gitadd [filepattern…]<br />Adds file contentstoyourstaging area<br />Usedfornewfiles and modificationstoexistingfiles<br />Possibletoskipthisoperation (withcommit–aoption)<br />Youusegitaddto start trackingfiles and to stage changestoalreadytrackedfiles i.e. wheneveryouwantto include file changes in the nextcommit<br />
  12. 12. Gitcommands<br />>git status [-s]<br />Shows the status of the files (working directory and staging area)<br />Givescontext and hints–displayswhich(butnothow) fileschanged<br />-soptiongives short output (with no hints–similartosvnst)<br />Youusegit statustoseeifanythinghasbeenmodified and/or stagedsince the last commit<br />
  13. 13. Gitcommands<br />>gitdiff [--cached / HEAD] [--stat] [filepath]<br />Shows a patch ofcontentchangedsince last commit and notyetstaged<br />--cachedoptionshows the stagedchanges, HEAD showsbothstaged and unstagedchanges<br />--statoptiongives short output<br />Youusegitdifftoseehow (linebyline) fileshavebeenmodified and/or stagedsince the last commit<br />
  14. 14. Gitcommands<br />>gitcommit [-a] [-m ‘commitmessage’]<br />Records a snapshotof the staging area in the currentbranch<br />-aoptionaddsto the snapshotall the unstagedchanges<br />-moptionallowstoinsert the commitmessagedirectly<br />Youusegitcommitto record a snapshotof the stagedchanges. Thissnapshot can thenbecompared, shared and revertedto, ifyouneedto<br />
  15. 15. Gitcommands<br />>git reset [--hard] <HEAD/commit> [--files…]<br />Unstageschangesthathavebeenstaged<br />With --hard options, the repositorychangesto the last commit state <br />Possibletounstage single files<br />Youusegit reset HEADtounstagefilespreviouslystagedwithgitadd, toavoidincludingthem in the nextcommit<br />
  16. 16. Gitcommands<br />>gitrm [--cached] [files…]<br />Removesfilesfrom the staging area – and from the working directory<br />--cachedoptionallowstoretain the file in the working directory<br />Youusegitrmtoremovefilesfrombeingtracked in Git<br />
  17. 17. Gitcommands<br />>gitmv <source> <destination><br />Has the samebehaviourof:<br />>gitrm--cached <source><br />>mv <source> <destination><br />>gitadd <destination><br />Youusegitmvtorenamefiles under versioncontrol<br />
  18. 18. Gitcommands<br />>gitbranch [-d <branchname>] [branchname]<br />A branchis a contextwhereyou can switch<br />Withoutarguments, itlists out the localbranches and points out the currentone<br />With a branchname, itcreates a newbranch– the default oneisnamed master<br />-doptionwilldeletebranchname<br />Youusegitbranchtolistcurrentbranches, create newbranches and deleteunnecessarybranches<br />
  19. 19. Gitcommands<br />>git checkout [[-b] <branchname>]/ [--files…]<br />Swithcestobranchname<br />-boptionwill create branchnameand switchimmediatelytoit<br />--followedbyone or more files, reverts the contentofthesefilesto the last commit state<br />Youusegit checkout toswitchamongbranches, optionallycreatingthem; youalsouseittorevert the data ofany file to the last commit<br />
  20. 20. Gitcommands<br />>gitmerge <branchname><br />Merges the diffsbetween the currentbranch and branchnameinto the currentone<br />The branchbranchnamedoesn’tchange<br />Youusegitmergeto combine anotherbranchcontextinto the currentone<br />
  21. 21. Gitcommands<br />>git log [--oneline] [--graph] [--decorate] [branchname]<br />Showscommithistoryofbranchname(the currentoneifnotspecified)<br />The --onelineoptionsshowsonly the first rowof the commitmessage<br />The --graphoptionshows a graphofbranches and merges<br />The --decorateoptionshows information on branchesinvolved in merges<br />Youusegit log tolist out the commithistory<br />
  22. 22. Gitcommands<br />>git remote [-v] [add <url> <alias>]/[rm <alias>]<br />Lists the remote repositoryaliasesstored, -voptionsalsoshows the urls<br />Possibletohavedifferentpush and fetchurls<br />addallowstoadd the repository at url under the local-remotealias<br />rmallowstoremove the alias local-remote<br />Youusegit remote tolist out the remote repositories and the urlsthey’re using. You can alsoadd and removelocal-remoterepositories<br />
  23. 23. Gitcommands<br />>gitfetch <alias/--all><br />Downloadsbranches and data from a remote repository<br />--alloptionallowsto download data fromall remote repositories<br />Cannot checkout a remote repository<br />Youusegitfetchtosynchronizeyourrepositorywith a remote repository, fetchingall the data notalreadyexisting in yourlocalrepository<br />
  24. 24. Gitcommands<br />>git pull <alias>/<--all><br />Fetchesfrom a remote repository and triestomergeitinto the currentbranch<br />Has the samebehaviourof:<br />>gitfetch <alias><br />>gitmerge <alias><br />Youusegit pull tosynchronizeyourrepositorywith a remote repository, fetchingall the data notalreadyexisting in yourlocalrepository and mergingitinto the currentbranch<br />
  25. 25. Gitcommands<br />>gitpush <alias> [branch]<br />Pusheslocalbranches and data to a remote repository<br />If no branchisspecified, the currentbranchisused<br />The localbranchtopushhastobe up-to-date<br />Youusegitpushto update a remote repositorywithchangesmadelocally<br />
  26. 26. Gitcommands<br />>gitrevert [-n] <HEAD/commit><br />Reverts the contentsof the currentbranchto the commitstate<br />Itmakes a newcommit on the currentbranch!<br />With-noptions the data isreverted and isn’tcommitted<br />Youusegitreverttorevert the data in the currentbranchto a specified state<br />
  27. 27. Gitcommands<br />>gitstash <save/pop><br />Allowsto record the current state of the working directory<br />Doesn’tmake a commit<br />Saveallowsto create a stash, pop puts the stashedchanges back on the working directory<br />Youusegitstashtotemporarilystash (and afterwordsrecover) the data in the currentbranch, e.gtoproceedwith a pull request<br />
  28. 28. Tips<br />Enable console colors<br />>gitconfig --global color.diff auto<br />>gitconfig --global color.status auto<br />>gitconfig --global color.branch auto<br />Set name and email<br />>gitconfig --global user.name <Name and Surname><br />>gitconfig --global user.email <email><br />Set aliasesforcommands, e.g.:<br />>gitconfig --global alias.history ‘log --oneline--graph--decorate’<br />>gitconfig --global alias.st ‘status -s’<br />>gitconfig --global alias.ci ‘commit-m’<br />>gitconfig --global alias.co checkout<br />
  29. 29. GitHub<br />Web-based hosting service for software developmentprojectsthatuseGit<br />Possibletohave public repositories (free iftheyrequirelessthan 300MB)<br />
  30. 30. GitHub– Create a repo<br />
  31. 31. GitHub– Create a repo<br />>mkdirhelp-example<br />>cd help-example<br />>gitinit<br />>touch README<br />>gitcommit -a –m ‘first commit’<br />>git remote addorigin git@github.com:tekkub/help-example.git<br />>gitpushorigin master<br />
  32. 32. GitHub–Push data<br />I can’tpush, “Permissiondenied (public key)”<br />Topush data, youhaveto set up a pairof SSH keys, and addyour public key in the account options on GitHub<br />You can alsoconfigureyourGitHub account locally:<br />>gitconfig --global github.user <username><br />>gitconfig --global github.token <token><br />You can findyourtoken under yourGitHub account settings<br />
  33. 33. A simple scenario<br />Alice createdherrepo, test, on github (seepreviousslides), containingthesefiles:<br />README foo.txtbar.txttest.c<br />Bob joinsher– and hehaswriteaccessto the repository:<br />>gitclone git@github.com/alice/test.git test<br />Bob workslocally, and makes a branch:<br />>cd test<br />>git checkout –btext-changes<br />Nowhehas2branches: master and text-changes<br />
  34. 34. A simple scenario<br />Bob modifiesfoo.txt and bar.txt; afterthatheruns:<br />>gitaddfoo.txt<br />>git status –s<br />Mbar.txt<br />Mfoo.txt<br />The file bar.txthasbeenmodifiedbutnotalreadystaged; howeverBob runs:<br />>gitcommit–a–m ‘modifiedtxtfiles’<br />>git status –sgives no output<br />Thesefileshavebeenmodifiedonly in text-changesbranch<br />
  35. 35. A simple scenario<br />Bob wantstomodifytest.c in a newbranch, withouthaving the *.txtfilesmodified<br />>git checkout master<br />>gitbranchsrc-changes<br />>git checkout src-changes<br />Bob modifies the file test.c and afterthatheruns:<br />>gitadd .<br />>gitcommit–m ‘modified test file’<br />Bob has3branches: master, text-changes, src-changes<br />
  36. 36. A simple scenario<br />Meanwhile, Alice modifies README and test.c, and runs:<br />>gitcommit–a–m ‘modifiedreadme and test.c’<br />>gitpushorigin<br />Bob triestomergetext-changeswithsrc-changes<br />>gitbranch<br />master<br />* src-changes<br />text-changes<br />>gitmergetext-changes<br />
  37. 37. A simple scenario<br />Bob triestopush the changesinto the origin<br />>git checkout master<br />>gitmergesrc-changes<br />>gitpushorigin<br />However, Bob can’tpush data to the origin, becauseheisnot up-to-date<br />>git pull<br />Whathappenswith the file test.c? BothAlice and Bob modifiedit<br />
  38. 38. A simple scenario<br />Gittriestomergecontents– and it’sverylikelytobeableto do it<br />IfGit can’tmergecorrectly, Bob willsee the classicmerging style on his copy oftest.c:<br /><<<<<<<<< yours: test.c<br />//Bob’scontent<br />=========<br />//Alice’scontent<br />>>>>>>>>> theirs: test.c<br />Aftermerging, Bob can pushhis data to the origin<br />>gitpushorigin<br />
  39. 39. What else?<br />Git Reference<br />Git Tutorial<br />Git User’s Manual<br />Pro Git Book<br />Git Community Book<br />GitHub Help<br />Egit - Eclipseplugin<br />Graphicalfrontend:<br />Windows, Linux (gtk), Mac OSX, Multi-platform<br />

×