Effective Git - EclipseCon 2011 tutorial

6,774 views

Published on

Effective Git - EclipseCon 2011 tutorial

Tutorial slides, the corresponding tutorial exercises are published here https://docs.google.com/leaf?id=0B4F_gjXVrHZVMzE5MWNmNjktMDcxMS00NDM3LWI4NDQtYmE1YzZkM2RkY2Rl&hl=en

0 Comments
8 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
6,774
On SlideShare
0
From Embeds
0
Number of Embeds
2,700
Actions
Shares
0
Downloads
203
Comments
0
Likes
8
Embeds 0
No embeds

No notes for slide

Effective Git - EclipseCon 2011 tutorial

  1. 1. Effective Git Tutorial EclipseCon 2011 http://eclipse.org/egit http://code.google.com/p/ gerrit Matthias Sohn (SAP) + = Stefan Lay (SAP) Chris Aniszczyk(Redhat) Shawn Pearce (Google)
  2. 2. Git <ul><li>… a distributed revision control system built by the Linux project to facilitate code review </li></ul><ul><li>Distributed means no central repository </li></ul><ul><ul><li>No central authority! </li></ul></ul><ul><ul><li>Easy offline usage </li></ul></ul><ul><ul><li>Easy to branch a project </li></ul></ul><ul><ul><li>Protected against manipulation by cryptographic hashes </li></ul></ul><ul><li>Really good at merging </li></ul><ul><ul><li>Coordination only needed &quot;after the fact ” </li></ul></ul><ul><ul><li>Easier to rejoin (or refresh) branches </li></ul></ul><ul><li>Structured around commits (i.e. patches) </li></ul><ul><ul><li>Tools for identifying problem commits (git bisect) </li></ul></ul><ul><ul><li>Tools for restructuring branches w/ specific commits </li></ul></ul>Copyright © M. Sohn, S. Lay, S. Zivkov, C. Halstrick, C. Aniszczyk, S. Pearce
  3. 3. Git at Eclipse <ul><li>Eclipse defined a roadmap to move to Git CVS has been deprecated </li></ul><ul><li>EGit is an Eclipse Team provider for Git </li></ul><ul><ul><li>http://www.eclipse.org/egit/ </li></ul></ul><ul><li>JGit is a lightweight Java library implementing Git </li></ul><ul><ul><li>http://www.eclipse.org/jgit/ </li></ul></ul><ul><li>The goal is to build an Eclipse community around Git. </li></ul><ul><li>EGit/JGit are still beta and we want to establish a feedback loop to improve the tooling. </li></ul>Copyright © M. Sohn, S. Lay, S. Zivkov, C. Halstrick, C. Aniszczyk, S. Pearce
  4. 4. Modern Code Review – What is it ? <ul><ul><li>When one developer writes code, another developer is asked to review that code </li></ul></ul><ul><ul><li>A careful line-by-line critique </li></ul></ul><ul><ul><li>Happens in a non-threatening context </li></ul></ul><ul><ul><li>Goal is cooperation, not fault-finding </li></ul></ul><ul><ul><li>Integral part of coding process </li></ul></ul><ul><ul><li>Otherwise this will happen: </li></ul></ul><ul><ul><li>Debugging someone else's broken code </li></ul></ul><ul><ul><li>– Involuntary code review: Not so good; emotions may flare </li></ul></ul>Guido van Rossum [1] [1] http://code.google.com/p/rietveld/downloads/detail?name=Mondrian2006.pdf Copyright © M. Sohn, S. Lay, S. Zivkov, C. Halstrick, C. Aniszczyk, S. Pearce
  5. 5. Code Review – Benefits <ul><ul><li>Four eyes catch more bugs </li></ul></ul><ul><ul><ul><li>Catch bugs early to save hours of debugging </li></ul></ul></ul><ul><ul><li>Mentoring of new developers / contributors </li></ul></ul><ul><ul><ul><li>Learn from mistakes without breaking stuff </li></ul></ul></ul><ul><ul><li>Establish trust relationships </li></ul></ul><ul><ul><ul><li>Prepare for more delegation </li></ul></ul></ul><ul><ul><li>Good alternative to pair programming </li></ul></ul><ul><ul><ul><li>asynchronous and across locations </li></ul></ul></ul><ul><ul><li>Coding standards </li></ul></ul><ul><ul><ul><li>Keep overall readability & code quality high </li></ul></ul></ul>Guido van Rossum [1] [1] http://code.google.com/p/rietveld/downloads/detail?name =Mondrian2006.pdf Copyright © M. Sohn, S. Lay, S. Zivkov, C. Halstrick, C. Aniszczyk, S. Pearce
  6. 6. Developer PC Gerrit git git git git Developer PC git git Hudson - clone repository - fetch / push changes - verify proposed changes - continuous integration builds Copyright © M. Sohn, S. Lay, S. Zivkov, C. Halstrick, C. Aniszczyk, S. Pearce
  7. 7. Developer PC git git Gerrit git git git git push improved change 10 Developer PC git git fetch change 23 to try it master change 12 change 10 change 23 submit accepted change 12 fetch master to get updates Copyright © M. Sohn, S. Lay, S. Zivkov, C. Halstrick, C. Aniszczyk, S. Pearce
  8. 8. Git Configuration Copyright © M. Sohn, S. Lay, S. Zivkov, C. Halstrick, C. Aniszczyk, S. Pearce
  9. 9. Git Concepts – config files <ul><ul><li>git config –l </li></ul></ul><ul><ul><li>git config –e </li></ul></ul><ul><ul><li>--system </li></ul></ul><ul><ul><li>--global </li></ul></ul>System <gitinst>/etc/gitconfig Global ~/.gitconfig Repository Specific .git/config Copyright © M. Sohn, S. Lay, S. Zivkov, C. Halstrick, C. Aniszczyk, S. Pearce
  10. 10. Basic Concepts Copyright © M. Sohn, S. Lay, S. Zivkov, C. Halstrick, C. Aniszczyk, S. Pearce
  11. 11. Making Changes <ul><ul><li>Structure in the file system </li></ul></ul><ul><ul><li>One working tree per repo </li></ul></ul><ul><ul><li>.git folder is the Git repo </li></ul></ul><ul><ul><li>Files/folders under the parent of .git are the working tree </li></ul></ul>Copyright © M. Sohn, S. Lay, S. Zivkov, C. Halstrick, C. Aniszczyk, S. Pearce
  12. 12. Making Changes <ul><ul><li>Checkout: populate working tree with the commit you want to start working from </li></ul></ul><ul><ul><li>most of the time you will checkout a branch </li></ul></ul><ul><ul><li> checkout the commit pointed to by the branch (aka: tip of the branch) </li></ul></ul><ul><ul><li>per file checkout means revert ! </li></ul></ul>Calculator .git <working tree> git checkout master Copyright © M. Sohn, S. Lay, S. Zivkov, C. Halstrick, C. Aniszczyk, S. Pearce
  13. 13. Making Changes <ul><ul><li>Just start doing your changes </li></ul></ul><ul><ul><li>modify, add, delete files </li></ul></ul><ul><ul><li>Tell Git which changes you intend to commit </li></ul></ul><ul><ul><ul><li>git add </li></ul></ul></ul><ul><ul><li>EGit helps by auto-detecting what you changed </li></ul></ul>Copyright © M. Sohn, S. Lay, S. Zivkov, C. Halstrick, C. Aniszczyk, S. Pearce
  14. 14. Committing Changes <ul><ul><li>git commit </li></ul></ul><ul><ul><li>Provide a commit message </li></ul></ul><ul><ul><ul><li>First line is header </li></ul></ul></ul><ul><ul><ul><li>separated by a blank line follows the body </li></ul></ul></ul><ul><ul><ul><li>last paragraph is for meta data in key: value format </li></ul></ul></ul><ul><ul><li>commit represents a version of the complete repository </li></ul></ul><ul><ul><li>commits are identified by a globally unique ID (SHA1) </li></ul></ul><ul><ul><li>If two Git repos both contain a commit with the same ID then the content in these two commits is identical </li></ul></ul>Copyright © M. Sohn, S. Lay, S. Zivkov, C. Halstrick, C. Aniszczyk, S. Pearce
  15. 15. Commits <ul><ul><li>Commit history </li></ul></ul><ul><ul><ul><li>B is successor of A </li></ul></ul></ul><ul><ul><ul><li>C is successor of B </li></ul></ul></ul>A B C Copyright © M. Sohn, S. Lay, S. Zivkov, C. Halstrick, C. Aniszczyk, S. Pearce
  16. 16. Branches <ul><ul><li>Branch is a named pointer to a commit </li></ul></ul><ul><ul><li>Commit command moves the pointer </li></ul></ul>A B C master A B C master D commit Copyright © M. Sohn, S. Lay, S. Zivkov, C. Halstrick, C. Aniszczyk, S. Pearce
  17. 17. Branches <ul><ul><li>The (branch) pointer can also be moved “manually” to any commit </li></ul></ul><ul><ul><ul><li>git reset </li></ul></ul></ul>A B C master D A B C master D reset B Copyright © M. Sohn, S. Lay, S. Zivkov, C. Halstrick, C. Aniszczyk, S. Pearce
  18. 18. Branches <ul><ul><li>What happens on next git commit ? </li></ul></ul><ul><ul><li>C and D continue to exist but they are not in the history of the master branch </li></ul></ul>A B C master D A B C master D E commit Copyright © M. Sohn, S. Lay, S. Zivkov, C. Halstrick, C. Aniszczyk, S. Pearce
  19. 19. Branches <ul><ul><li>Usually there are many branches in a Git repository </li></ul></ul><ul><ul><li>Branches can also be deleted </li></ul></ul>A B C origin/master D E feature 1 F bugfix 15 G feature 2 Copyright © M. Sohn, S. Lay, S. Zivkov, C. Halstrick, C. Aniszczyk, S. Pearce
  20. 20. HEAD <ul><ul><li>HEAD – pointer to a branch </li></ul></ul><ul><ul><li>Means: “Current Branch” – the branch which you have checked out </li></ul></ul>A B C D E feature 1 F bugfix 15 HEAD origin/master Copyright © M. Sohn, S. Lay, S. Zivkov, C. Halstrick, C. Aniszczyk, S. Pearce
  21. 21. Cloning & Fetching Copyright © M. Sohn, S. Lay, S. Zivkov, C. Halstrick, C. Aniszczyk, S. Pearce
  22. 22. Clone Remote Repository <ul><ul><li>git clone <remote-repo> </li></ul></ul><ul><ul><li>Git is a distributed versioning system </li></ul></ul><ul><ul><li>cloned repo gets local name “origin” (by default) </li></ul></ul>A B C master D E F HEAD feature-1 A B C master D E F HEAD origin/feature-1 origin/master Remote “origin” Local clone clone Copyright © M. Sohn, S. Lay, S. Zivkov, C. Halstrick, C. Aniszczyk, S. Pearce
  23. 23. Clone Remote Repository <ul><ul><li>Remote tracking branches, full names: </li></ul></ul><ul><ul><li>remotes/origin/master </li></ul></ul><ul><ul><li>remotes/origin/feature-1 </li></ul></ul>A B C master D E F HEAD origin/feature-1 origin/master Local clone Copyright © M. Sohn, S. Lay, S. Zivkov, C. Halstrick, C. Aniszczyk, S. Pearce
  24. 24. Remote Tracking Branches <ul><ul><li>Just like any other branch, but read-only </li></ul></ul><ul><ul><li>possible: git checkout origin/feature1 </li></ul></ul><ul><ul><li>However, HEAD gets detached! </li></ul></ul>A B C master D E F HEAD origin/feature-1 origin/master Copyright © M. Sohn, S. Lay, S. Zivkov, C. Halstrick, C. Aniszczyk, S. Pearce
  25. 25. Fetch <ul><ul><li>git fetch will update all remote tracking branches to reflect the changes done in the “origin” repo </li></ul></ul>A B C master D E F HEAD feature-1 Remote “origin” G feature-1 A B C master D E F HEAD origin/feature-1 origin/master Local clone G origin/feature-1 fetch Copyright © M. Sohn, S. Lay, S. Zivkov, C. Halstrick, C. Aniszczyk, S. Pearce
  26. 26. Fetch <ul><ul><li>Always safe to do </li></ul></ul><ul><ul><li>Updates only remote tracking branches </li></ul></ul><ul><ul><li>Does never change local branches </li></ul></ul>Copyright © M. Sohn, S. Lay, S. Zivkov, C. Halstrick, C. Aniszczyk, S. Pearce
  27. 27. Merge & Rebase Copyright © M. Sohn, S. Lay, S. Zivkov, C. Halstrick, C. Aniszczyk, S. Pearce
  28. 28. Merge <ul><ul><li>git merge feature-1 </li></ul></ul><ul><ul><li>will replay all changes done in feature-1 since it diverged from 1.0 (E and F) </li></ul></ul>A B C D E F HEAD feature-1 A B C 1.0 D E F HEAD feature-1 G 1 2 1 2 1.0 merge feature-1 Copyright © M. Sohn, S. Lay, S. Zivkov, C. Halstrick, C. Aniszczyk, S. Pearce
  29. 29. Merge <ul><ul><li>git merge feature-1 </li></ul></ul><ul><ul><li>Easy Case - Fast Forward </li></ul></ul><ul><ul><li>no new commit, just move the pointer </li></ul></ul>A B E HEAD feature-1 A B E HEAD feature-1 1.0 1.0 merge feature-1 Copyright © M. Sohn, S. Lay, S. Zivkov, C. Halstrick, C. Aniszczyk, S. Pearce
  30. 30. Cherry Pick <ul><ul><li>git cherry-pick F </li></ul></ul><ul><ul><li>applies changes introduced by F, means delta-2 </li></ul></ul><ul><ul><li>no merge relation </li></ul></ul>A B C 1.0 D E F HEAD feature-1 1 2 A B C 1.0 D E F HEAD feature-1 G 2 cherry-pick F Copyright © M. Sohn, S. Lay, S. Zivkov, C. Halstrick, C. Aniszczyk, S. Pearce
  31. 31. Rebase <ul><ul><li>git rebase 1.0 </li></ul></ul><ul><ul><li>alternative to merge - keeping history linear </li></ul></ul><ul><ul><li>after rebase fast-forward possible! </li></ul></ul>A B C 1.0 D E F HEAD feature-1 A B C 1.0 D E ’ F ’ HEAD feature-1 1 2 1 2 rebase 1.0 Copyright © M. Sohn, S. Lay, S. Zivkov, C. Halstrick, C. Aniszczyk, S. Pearce
  32. 32. Pushing Copyright © M. Sohn, S. Lay, S. Zivkov, C. Halstrick, C. Aniszczyk, S. Pearce
  33. 33. Push <ul><ul><li>git push origin HEAD:master </li></ul></ul><ul><ul><li>from local to remote repository </li></ul></ul><ul><ul><li>more precisely: from a local to a remote branch </li></ul></ul>A B origin/master C Local repo feature-1 HEAD A B C master Remote “origin” repo push Copyright © M. Sohn, S. Lay, S. Zivkov, C. Halstrick, C. Aniszczyk, S. Pearce
  34. 34. Push <ul><ul><li>Which commits get pushed? </li></ul></ul><ul><ul><li>ALL commits from the local branch not available in the remote branch </li></ul></ul>A B origin/master C Local repo feature-1 HEAD D A B C master D Remote “origin” repo push Copyright © M. Sohn, S. Lay, S. Zivkov, C. Halstrick, C. Aniszczyk, S. Pearce
  35. 35. Push <ul><ul><li>Remote branch has changed </li></ul></ul><ul><ul><li>git push will fail because fast forward is not possible </li></ul></ul>A B origin/master C Local repo feature-1 HEAD A B D master Remote “origin” repo push Copyright © M. Sohn, S. Lay, S. Zivkov, C. Halstrick, C. Aniszczyk, S. Pearce
  36. 36. Push <ul><ul><li>Possibility One </li></ul></ul><ul><ul><li>pull ( fetch + merge ), push </li></ul></ul>A B origin/master C Local repo feature-1 HEAD A B D master Remote “origin” repo D E C E push Copyright © M. Sohn, S. Lay, S. Zivkov, C. Halstrick, C. Aniszczyk, S. Pearce
  37. 37. Push <ul><ul><li>Possibility Two </li></ul></ul><ul><ul><li>fetch, rebase, push </li></ul></ul>A B origin/master Local repo feature-1 HEAD D C ’ A B D master Remote “origin” repo C ’ push Copyright © M. Sohn, S. Lay, S. Zivkov, C. Halstrick, C. Aniszczyk, S. Pearce
  38. 38. Push <ul><ul><li>Which graph do you like more ? </li></ul></ul>A B D master Remote “origin” repo C E A B D master C ’ Remote “origin” repo Copyright © M. Sohn, S. Lay, S. Zivkov, C. Halstrick, C. Aniszczyk, S. Pearce
  39. 39. Gerrit Concepts Copyright © M. Sohn, S. Lay, S. Zivkov, C. Halstrick, C. Aniszczyk, S. Pearce
  40. 40. Push <ul><ul><li>Push to Gerrit is the same like push to Git </li></ul></ul><ul><ul><li>with one Gerrit speciality: refs/for in the target branch name </li></ul></ul><ul><ul><li>Compare: </li></ul></ul><ul><ul><li>Push to Git: git push origin HEAD:master </li></ul></ul><ul><ul><li>Push to Gerrit: git push origin HEAD: refs/for /master </li></ul></ul>Copyright © M. Sohn, S. Lay, S. Zivkov, C. Halstrick, C. Aniszczyk, S. Pearce
  41. 41. Push <ul><li>It seems like every push to Gerrit goes to the same branch refs/for/master </li></ul><ul><li>However, Gerrit tricks your git client: </li></ul><ul><ul><li>it creates a new branch for the commit(s) you push </li></ul></ul><ul><ul><li>and creates a new open Gerrit change for each pushed commit </li></ul></ul>Copyright © M. Sohn, S. Lay, S. Zivkov, C. Halstrick, C. Aniszczyk, S. Pearce
  42. 42. Push <ul><ul><li>git push origin HEAD:refs/for/master </li></ul></ul>A B origin/master C Local repo feature-1 HEAD A B C master Gerrit hosted “origin” repo refs/changes/63/363/1 Gerrit DB - Open Changes: … {Change-ID = 1234, Patch-Set-1 = refs/changes/63/363/1 } … Copyright © M. Sohn, S. Lay, S. Zivkov, C. Halstrick, C. Aniszczyk, S. Pearce
  43. 43. Push <ul><ul><li>What if feature branch has 2 commits ? </li></ul></ul><ul><ul><li>Remember Git semantics for Push? </li></ul></ul><ul><ul><li>ALL commits from the local branch not available in the remote branch  2 changes in Gerrit ! </li></ul></ul>A B origin/master C Local repo feature-1 HEAD D A B C master Gerrit hosted “origin” repo refs/changes/63/363/1, Change 1234 D refs/changes/64/364/1, Change 1235 depends on Copyright © M. Sohn, S. Lay, S. Zivkov, C. Halstrick, C. Aniszczyk, S. Pearce
  44. 44. Changes <ul><ul><li>Change consists of </li></ul></ul><ul><ul><li>Change ID (important!) </li></ul></ul><ul><ul><li>metadata (owner, project, etc..) </li></ul></ul><ul><ul><li>one or more patch-sets </li></ul></ul><ul><ul><li>comments </li></ul></ul><ul><ul><li>votes </li></ul></ul><ul><ul><li>Patch Set represents a Git Commit </li></ul></ul>Copyright © M. Sohn, S. Lay, S. Zivkov, C. Halstrick, C. Aniszczyk, S. Pearce
  45. 45. New Change vs New Patch Set <ul><ul><li>How does Gerrit know whether to create a new Change or a new Patch Set for an existing change? </li></ul></ul><ul><ul><li>It looks at the Commit Message and searches for String “Change-Id: <ISHA1>” in the last paragraph of the commit message </li></ul></ul><ul><ul><li>If found it will create a new patchset for this changes, otherwise it will create a new change </li></ul></ul>Copyright © M. Sohn, S. Lay, S. Zivkov, C. Halstrick, C. Aniszczyk, S. Pearce
  46. 46. New Change vs New Patch Set <ul><ul><li>Example Commit Message with Change-Id: </li></ul></ul>Make lib.Repository abstract and lib.FileRepository its implementation To support other storage models other than just the local filesystem, … will rename it into storage.file.FileRepository, but to do that we need to also move a number of other related class, which we aren't quite ready to do. Change-Id: I1bd54ea0500337799a8e792874c272eb14d555f7 Signed-off-by: Joe Developer <joe@example.org> Copyright © M. Sohn, S. Lay, S. Zivkov, C. Halstrick, C. Aniszczyk, S. Pearce
  47. 47. Push New Patchset <ul><ul><li>No dependencies between Patchsets </li></ul></ul><ul><ul><li>can ’t push a successor commit as the next patchset </li></ul></ul><ul><ul><li>commit D can ’t be Patch Set 2 of change 1234 </li></ul></ul>A B origin/master C Local repo feature-1 HEAD D Change 1234, Patch Set 1 Copyright © M. Sohn, S. Lay, S. Zivkov, C. Halstrick, C. Aniszczyk, S. Pearce
  48. 48. Push New Patchset <ul><ul><li>If you pushed C and need to replace it by a new commit as a new patchset use </li></ul></ul><ul><ul><ul><li>git commit –amend </li></ul></ul></ul><ul><ul><li>with –amend option the new commit replaces the current instead of becoming successor </li></ul></ul>A B origin/master C Local repo feature-1 HEAD Change 1234, Patch Set 1 A B origin/master C Local repo feature-1 HEAD D Change 1234, Patch Set 1 Copyright © M. Sohn, S. Lay, S. Zivkov, C. Halstrick, C. Aniszczyk, S. Pearce
  49. 49. Push New Patch Set <ul><ul><li>A Common Mistake </li></ul></ul><ul><ul><li>author of the Patch Set 1 is not available and somebody else needs to continue and provide Patch Set 2 </li></ul></ul><ul><ul><li>use git pull to get the Patch Set 1 into a local branch </li></ul></ul><ul><ul><li>Fix issues in commit </li></ul></ul><ul><ul><li>Push (including the same Change-Id) </li></ul></ul><ul><ul><li>Gerrit rejects! </li></ul></ul>Copyright © M. Sohn, S. Lay, S. Zivkov, C. Halstrick, C. Aniszczyk, S. Pearce
  50. 50. Push New Patchset <ul><ul><li>A Common Mistake </li></ul></ul><ul><ul><li>git pull origin refs/changes/66/366/1 </li></ul></ul><ul><ul><li>D is successor of C and cannot be Patch Set 2 </li></ul></ul>A B Local repo HEAD A B C Local repo Change 1234, Patchset 1 master D HEAD master Copyright © M. Sohn, S. Lay, S. Zivkov, C. Halstrick, C. Aniszczyk, S. Pearce
  51. 51. Push New Patch Set <ul><ul><li>The right way: </li></ul></ul><ul><ul><li>fetch (don ’t pull ) </li></ul></ul><ul><ul><li>create a new branch based on the fetched patchset 1 </li></ul></ul><ul><ul><li>fix the issue </li></ul></ul><ul><ul><li>commit –amend </li></ul></ul><ul><ul><li>push </li></ul></ul>Copyright © M. Sohn, S. Lay, S. Zivkov, C. Halstrick, C. Aniszczyk, S. Pearce
  52. 52. Push New Patchset <ul><ul><li>The right way: </li></ul></ul><ul><ul><li>commit D is not successor of C </li></ul></ul><ul><ul><li>D can become patchset 2 </li></ul></ul>A B C Local repo Change 1234, Patch Set 1 D HEAD feature-1 A B C Local repo Change 1234, Patch Set 1 HEAD feature-1 Copyright © M. Sohn, S. Lay, S. Zivkov, C. Halstrick, C. Aniszczyk, S. Pearce
  53. 53. Review and Vote <ul><ul><li>Explore the Gerrit Web UI </li></ul></ul><ul><ul><li>Click “Review” to vote or comment </li></ul></ul><ul><ul><li>Voting the lowest mark means Veto </li></ul></ul><ul><ul><li>Highest marks in all voting categories needed for change to be merged </li></ul></ul><ul><ul><li>“ Submit” to merge accepted change into master </li></ul></ul>Copyright © M. Sohn, S. Lay, S. Zivkov, C. Halstrick, C. Aniszczyk, S. Pearce
  54. 54. Fetch Open Change Locally <ul><ul><li>Don ’t forget that every patchset is a commit </li></ul></ul><ul><ul><li>Use git fetch to fetch it locally if you want to play with it </li></ul></ul><ul><ul><li>Hudson Gerrit plugin does just that ! </li></ul></ul><ul><ul><li>Gerrit creates fetch command for you </li></ul></ul><ul><ul><li>In EGit use “Fetch from Gerrit…” </li></ul></ul>Copyright © M. Sohn, S. Lay, S. Zivkov, C. Halstrick, C. Aniszczyk, S. Pearce
  55. 55. Best Practices <ul><ul><li>Create local branch for each feature or bugfix you work on </li></ul></ul><ul><ul><li>branch name tells you what your intention was </li></ul></ul><ul><ul><li>less likely you will mix two features in the same branch </li></ul></ul><ul><ul><li>you can have many feature branches at a time </li></ul></ul><ul><ul><li>and switch between them </li></ul></ul>Copyright © M. Sohn, S. Lay, S. Zivkov, C. Halstrick, C. Aniszczyk, S. Pearce
  56. 56. Best Practices <ul><ul><li>Push finished features only </li></ul></ul><ul><ul><li>who wants to review non finished feature ? </li></ul></ul><ul><ul><li>who wants non-finished features in history ? </li></ul></ul><ul><ul><li>Push complete feature as one commit </li></ul></ul><ul><ul><li>even if you created many commits squash them into one before push </li></ul></ul><ul><ul><li>otherwise you create one change in Gerrit per each commit ! </li></ul></ul><ul><ul><li>use multiple changes if feature can be split into smaller logical units and use last change to switch on the new feature </li></ul></ul>Copyright © M. Sohn, S. Lay, S. Zivkov, C. Halstrick, C. Aniszczyk, S. Pearce
  57. 57. Best Practices <ul><ul><li>Write good commit message </li></ul></ul><ul><ul><li>First line is summary </li></ul></ul><ul><ul><li>Empty line after summary and between paragraphs </li></ul></ul><ul><ul><li>Explain WHY you did the change not WHAT you did (this is visible from the commit) </li></ul></ul><ul><ul><li>Prefer many small changes to one big </li></ul></ul><ul><ul><li>still each small change must be logically complete </li></ul></ul>Copyright © M. Sohn, S. Lay, S. Zivkov, C. Halstrick, C. Aniszczyk, S. Pearce

×