Git šŸ”€

JiÅ™Ć­ Urban, TomĆ”Å” Juřička, Stanislav ČermĆ”k, KarolĆ­na NesrstovĆ”, David Dlugosz, TomĆ”Å” Trčka

Commit vs. Push ā“

  • Commit
    • Saves repo changes on local repo
  • Push
    • Commit + sends changes to remote repo

Fetch vs. Pull ā“

  • Fetch
    • Downloads changes from the remote to your local repo
  • Pull
    • Fetch + merges them into your current branch

Head šŸ‘ˆ

  • Pointer to (the latest) commit

Working directory šŸ“
/ tree / copy

  • Dir on local machine where Git repo was cloned or inited
  • You can make changes here
  • Can be lost when switching branches or pulling changes

Checkout branch āœ…

  • Switch to a different branch in your repo
  • Make it ā€˜activeā€™ so you can make changes there
    Ā 
  • Git updates files in your working dir
  • Changes are then specific to that branch

Stash changes

  • Save changes to the working dir which are not yet committed

  • Allow to temporarily switch to another branch

Stage changes

  • Preparing changes to be included in the next commit

Git Merge Conflict āš”ļø

  • Attempt to merge two branches with conflicting changes
  • Auto merge fails
  • Manually resolve the changes
    Ā 
  • Can be time-consuming
  • Avoid as much as possible

Pull request vs. Merge request ā“

  • Same result
  • GitHub ~ pull r.
  • GitLab ~ merge r.
  • Reviewer (approve / reject)

Squash commits

  • Combine multiple commits into a single commit
  • Cleaner and more organized history

Git merge vs. rebase

  • Both solve the same problem (forked commit history)
  • Integrate changes from one branch into another (but in different ways)

Git merge

  • Merge the ā€˜mainā€™ branch into the feature branch
  • Creates new commit in the ā€˜featureā€™ branch
  • Easier
  • Non-destructive operation
  • Existing branches arenā€™t changed
  • But: additional merge commit

Git rebase

  • Rebase ā€˜featureā€™ branch onto ā€˜mainā€™
  • Moves the entire ā€˜featureā€™ branch at the end of the ā€˜mainā€™
  • Re-writes the project history
  • Creates brand new commits

    for each commit in the original branch

  • Much cleaner history

  • Linear project history
    without forks

  • But: safety + traceability

Git rebase 2 - Safety

  • Never rebase on public branches (e. g. ā€˜mainā€™ onto ā€˜featureā€™)

  • My ā€˜mainā€™ diverged from othersā€™ main

  • Would have to merge them
    back together

  • ā€œIs anyone else looking
    at this branchā€?

  • If no, you can rebase

Git rebase 3 - Traceability

  • Less important
  • Loses the context provided by a merge commit
  • Canā€™t see when upstream changes were merged into ā€˜featureā€™

Git Flow

  • = Branching model (vs. trunk-based workflows)
  • Feature branches
  • Multiple primary branches
  • Longer-lived branches
  • Larger commits
  • Higher risk of conflicting updates

Branches šŸŒ³
(from start to end of a project)

  • Main
    • Formerly ā€˜Masterā€™ ā“
    • Production-ready code that can be released
  • Develop
    • Pre-production code with new features which are being tested

Branches šŸŽ„ (supporting)

  • Feature
    • Most common
    • Working on a new feature
    • Based on: Develop
    • Merged to: Develop (after review)
  • Release branch
    • Preparing new production releases
    • Finishing touches + minor bugs specific to release
  • Hotfix branch
    • Quickly address necessary changes in Main branch
    • Based on: Main
    • Merged to: Main + Develop

Ā 

Git tag šŸ·ļø

  • Label to mark a specific point in the history (e. g. version)

  • = Reference to a specific commit

Best practices šŸ†
(clean and well-organized)

  • Commits small and focused
  • Branches to isolate changes
  • Meaningful commit messages
  • Regular fetch / pull
  • Review before merge
  • Use tags to mark releases
  • Use ā€˜.gitignoreā€™ file (build artifacts, generated files)
  • Use one branching strategy (by all members)

Best practices 2 šŸŽ–ļø

  • Do not nest (feature) branches
  • Merge (feature) branches as soon as possible

GUI git tools šŸ› ļø

  • Sourcetree ā€“ free, for WIN and MAC
  • GitKraken ā€“ cross platform, integrates with GitHub, Bitbucket, GitLab
  • GitHub Desktop
  • GitLab ā€“ web-based git repo manager (DevOps platform, CI/CD, wiki)
  • Bitbucket ā€“ web-based git repo manager by Atlassian, integrates with Jira, Confluence

  • TortoiseGit ā€“ Win-based, integrates with Win explorer

Made with Slides.com