.NET Day 19 - Git for Fun - getting productive with git by Michael Kaufmann

.NET Day 19 - Git for Fun - getting productive with git by Michael Kaufmann

Git has won the battle of version control systems and is widespread – not only in the open source world. But many teams do not get the maximum productivity out of it, because they did not approach git with the right strategies. The talk presents the best strategies for the entire git workflow – from branch and commit over review to merge. The talk helps you answer question like: How do you find a branching workflow that fits your Team? How do you ensure consistent naming? How do you write meaningful commit messages? What’s the best merge strategy for your team? How do you optimize your review process with pull requests? The version control system is the base for all development – so get the best out of it and get productive with your team.

E6cffbf3b7a5fbfee4707033ef1636f5?s=128

dotnetday

May 28, 2019
Tweet

Transcript

  1. Git for Fun getting productive with git Michael kaufmann, Director

    DevOps & Innovation
  2. 2 Blog: http://writeabout.net Twitter: @mike_kaufmann Michael Kaufmann Director DevOps &

    Innovation
  3. Ever committed your password to GitHub?

  4. productive productive adjective 1. having the power of producing; generative;

    creative: a productive effort. 2. producing readily or abundantly; fertile: a productive vineyard. … 4
  5. 5 „If git did not change the way you work,

    you are doing it wrong!“ 33 Mio Developers on GitHub
  6. 6 „If git did not change the way you work,

    you are doing it wrong!“ 80-90% open source in new applications
  7. 7 „If git did not change the way you work,

    you are doing it wrong!“ 15K+ OSS packages released daily
  8. “I’m an egotistical bastard, and I name all my projects

    after myself. First ‘Linux’, now ‘Git’.” – Linus Torvalds 8 Git Started… What is Git? • Git (/ɡɪt/): • “A completely ignorant, childish person with no manners” • Since:2005 • License: GPL-2.0-only • Distributed version-control Bild: Silicon News, YouTube
  9. Git Started… Repos and prices: Azure Repos 9 Unlimited private

    Git repo hosting and support for TFVC that scales from a hobby project to the world’s largest Git repositories Works with your Git client Securely connect with and push code into your Git repos from any IDE, editor, or Git client. Web hooks and API integration Add validations and extensions from the marketplace or build your own using web hooks and REST APIs. Semantic code search Quickly find what you’re looking for with code- aware search that understands classes and variables.
  10. Git Started… Repos and pricese: Azure Repos 10 Open source

    Unlimited users and build time Azure Pipelines: 10 • Azure Pipelines: 10 parallel jobs with unlimited minutes • Azure Boards: Work item tracking and Kanban boards • Azure Repos: Unlimited public Git repos Small Teams Start free with up to 5 usersAzure Pipelines: 1 • Azure Pipelines: 1 hosted job with 1,800 minutes per month • Azure Boards: Work item tracking and Kanban boards • Azure Repos: Unlimited private Git repos • Azure Artifacts: 2GB for all your Maven, npm, NuGet, Python, and Universal packages • Load testing (20,000 VUMs/month) • Unlimited stakeholders Teams Teams of any size • Azure Pipelines: 1 hosted job with 1,800 minutes per month for CI/CD and 1 self-hosted job • Azure Boards: Work item tracking and Kanban boards • Azure Repos: Unlimited private Git repos • Azure Artifacts: 2GB for all your Maven, npm, NuGet, Python, and Universal packages • Load testing (20,000 VUMs/month) • Unlimited stakeholders • Visual Studio subscribers included free Free Free $6 / Monat https://azure.microsoft.com/en-us/pricing/details/devops/azure-devops-services/
  11. Git Started… Repos und Preise: GitHub 11 Unlimited private Git

    repo hosting that scales from a hobby project to the world’s largest Git repositories Works with your Git client Securely connect with and push code into your Git repos from any IDE, editor, or Git client. Web hooks and API integration Add validations and extensions from the marketplace or build your own using web hooks and REST APIs. Semantic code search Quickly find what you’re looking for with code- aware search that understands classes and variables.
  12. 0 EUR $7 / Monat $9 / Monat $21 /

    Monat • Unlimited public repositories • Unlimited private repositories • 3 collaborators for private repositories • Issues and bug tracking • Project management • Unlimited public repositories • Unlimited private repositories • Unlimited collaborators • Issues and bug tracking • Project management • Unlimited public repositories • Unlimited private repositories • Team access controls • User management and billing • Unlimited collaborators • Issues and bug tracking • Project management • Self-hosted or cloud- hosted • SAML single sign-on • Access provisioning • Simplified account administration • Unified search and contributions • Priority support • 99.95% uptime SLA for Enterprise Cloud • Invoice billing • Advanced auditing Git Started… Repos und Preise: GitHub 12 Kostenlos Pro Team Enterprise
  13. Organization Git Guidelines Team Git guidance Performance The turbo for

    Git… 13
  14. 1 Organization… 14

  15. „With great power comes great responsibility“ Git guidelines for organizations

    15
  16. 16 Flexibility

  17. 17 Alignment

  18. 18 Git guidelines for organizations • „With great power comes

    great responsibility“ • Flexibility vs. Alignment (across teams) • Minimal guideline + Guidance for Teams
  19. 19 Git-Flow

  20. 20

  21. Trunk-Based-Development

  22. • Trunk-Based-Dev. (TBD) Mainline-Dev. (MLD) GitHub-Flow • Keep a high-quality

    master branch that is locked by policies. • Use topic branches for all new features and bug fixes • Merge branches into master using a pull request Git guidelines for organizations 22
  23. 23 Trunk-Based-Development bugfixes/important-bug-fix features/my-new-feature merge

  24. Demo: Pull-Request in Action

  25. • Topic-Branches • features/feature-name • features/feature-area/feature-name • bugfix/description • hotfix/description

    • users/username/description • users/username/workitem • … 25 Git guidelines for organizations Tip: Control naming conventions by forcing rights for folders: https://github.com/wulfland/ScriptRepo sitory/blob/master/Set- RepositoryPermission/Set- RepositoryPermission.ps1
  26. • Branch-Policies • Reviewers • Linked WorkItems • Comment Resolution

    • Merge Strategy Git guidelines for organizations 26
  27. Shows commits as separate path Merge Strategy 27 No-Fast-Forward Merge

    git merge pr --no-ff Squash Merge git merge pr --squash No commits
  28. Cherry-pick each commit into master Merge Strategy 28 Rebase git

    rebase master; git merge pr --ff-only Semi-linear merge git rebase master; merge pr --no-ff individual commits seperated
  29. • Branch-Policies • Build-Policies • Status-Policies • Automatically included code

    reviewers Git guidelines for organizations 29
  30. 2 Team… 30

  31. • Review und Merge • Two reviewers minimum • Integrate

    into existing review process • Share responsibility • Provide good descriptions • Build / Deploy your changes in the PR • Code-Of-Conduct • „Automated Reviewers“ for consitency across teams (i.e. IaC, CD etc.) 32 Git – guidance for teams
  32. Git – guidance for teams 33 Mono Repo A „monolith“

    Repo Multi-Repo Many small repos •Root • Module1 • src • test • Readme.md • Module2 • src • test • Readme.md • … •Readme.md team-app-<int/type>-module Team A prefix for all repos that keep them together in your local repo folder. Application The short name of your application Optional: interface/ type For example: by type (Packages like nugget or npm) or interface (REST service, message based) Module The name of the module
  33. • How do I stabilize my release with a manual

    test phase without git flow? Git – guidance for teams 34
  34. • Don‘t use tags! • Use release branches: • Long-lived

    • One-way • Cherry-Picking Git – guidance for teams 35
  35. bufix/name release/666 36 Release-Branches hotfix/name master „cherry-picking“

  36. • How do I deal with features that, • take

    a long time to develop? • have dependencies on other systems? Git – guidance for teams 37
  37. • Use Feature Flags (a.k.a. Feature Toggles or Feature Switches)

    Git – guidance for teams 38
  38. Feature Flags: Decouple the roll-out of functionality from the deployment

    of code 39 Git – guidance for teams
  39. • Commits: • SRP • Small • Focused • Be

    careful with refactoring and/or whitespaces • Messages • Present tense? • Punctation? • Define standards Git – guidance for teams 40
  40. • Dos: • Pull-Requests • CI/CD • Git-Hooks • Don‘ts:

    • Submodules • Tags • Long-Lived-Branches Git für Teams – Guidance 41
  41. • Security • Formating • Guidelines • Etc. 42 GitHooks

    https://www.visualstudiogeeks.com/DevOps/UsingPowerShellForGitHooksWithVstsGitOnWindows
  42. 3 Performance… 43

  43. • Do learn Git on the console! • Find your

    comfort console (Bash, PowerShell, CmdEr, posh-git) • Do use Git-Aliase • Use the editor of your choice! Performance… Getting productive with git 44
  44. • Git-Aliase • git config --global alias.co checkout • git

    config --global alias.br branch • git config --global alias.ci commit • git config --global alias.st status • git config --global alias.unstage 'reset HEAD --’ • git config --global alias.last 'log -1 HEAD' Performance… Getting productive with git 45
  45. • Git-Aliase (Advanced) • my_alias = "!f() { 〈your complex

    command〉 }; f“ • $1, $1, $3,…, $@ • Bsp: fb = “!f(){ git checkout –b features/$1 };f” Performance… Getting productive with git 46
  46. • Git-Editor git config --global core.editor "code --wait" Performance… Getting

    productive with git 47
  47. Demo: Productive with the console

  48. “Oh shit, I did something terribly wrong, please tell me

    git has a magic time machine!?!” git reflog git reset ‘HEAD@{index}’ Oh Shit, Git! 49 https://ohshitgit.com/
  49. “Oh shit, I did something terribly wrong, please tell me

    git has a magic time machine!?!” git reflog git reset ‘HEAD@{index}’ Oh Shit, Git! 50 https://ohshitgit.com/
  50. “Oh shit, I need to change the message on my

    last commit!” git commit --amend [-m “New Msg”] Oh Shit, Git! 51 https://ohshitgit.com/
  51. “Oh shit, I accidentally committed to the wrong branch!” git

    reset HEAD~ --soft; git stash git checkout –b new-branch; git stash pop Git add .;git commit –m „…“ Oh Shit, Git! 52 https://ohshitgit.com/
  52. “TL;DR” cd.. Remove-Item <folder> -Recurse –Force Git clone <url> Oh

    Shit, Git! 53 https://ohshitgit.com/
  53. Organization Git Guidelines Team Git guidance Performance The turbo for

    Git… 54
  54. 55 „If git did not change the way you work,

    you are doing it wrong!“
  55. 56