Upgrade to Pro — share decks privately, control downloads, hide ads and more …

.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.

dotnetday

May 28, 2019
Tweet

More Decks by dotnetday

Other Decks in Technology

Transcript

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

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

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

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

    you are doing it wrong!“ 15K+ OSS packages released daily
  5. “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
  6. 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.
  7. 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/
  8. 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.
  9. 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
  10. 18 Git guidelines for organizations • „With great power comes

    great responsibility“ • Flexibility vs. Alignment (across teams) • Minimal guideline + Guidance for Teams
  11. 20

  12. • 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
  13. • 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
  14. • Branch-Policies • Reviewers • Linked WorkItems • Comment Resolution

    • Merge Strategy Git guidelines for organizations 26
  15. 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
  16. 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
  17. • 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
  18. 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
  19. • How do I stabilize my release with a manual

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

    • One-way • Cherry-Picking Git – guidance for teams 35
  21. • How do I deal with features that, • take

    a long time to develop? • have dependencies on other systems? Git – guidance for teams 37
  22. • Commits: • SRP • Small • Focused • Be

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

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

    https://www.visualstudiogeeks.com/DevOps/UsingPowerShellForGitHooksWithVstsGitOnWindows
  25. • 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
  26. • 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
  27. • 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
  28. “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/
  29. “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/
  30. “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/
  31. “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/
  32. 56