Git Branching and Merging

https://www.pluralsight.com/courses/git-branching-merging

by Craig Golightly 

Module 1: Course Overview

  1. Course Overview

Module 2: Understanding Git Branch Basics

  1. About This Course
    • Github Default Branch Naming
      • Oct 2020 changed default from master to main
      • Organizations can set a default branch name
  2. Branching In-flight
    • 'git init' will create a new git repo
    • shows an example of creating a branch after making changes
      • 'git checkout -b {branch name}' will create a new branch and move pending changes into new branch
    • to switch back to main: 'git checkout main'
  3. Moving from Branch to Branch
    • 'git branch': List your branches
    • 'git checkout' or 'git switch' to swtich to a different branch
    • When you've made changes to a branch,  but you've not yet committed those changes to the branch (a dirty branch), Git won't let you switch from a dirty branch that has uncommitted changes until you clean up your changes.
    • 'git status' shows your current branch
  4. Renaming and Deleting Branches
    • to Rename a Branch - git branch -m <current name> <new name>
    • to rename current branch -  git branch -m <new name for current branch>
    • to delete a branch - git branch -d <branchname>
      • commits must first be merged
        • however, you can override by using the -D flag
Module 3: Merging Made Easy
  1. Comparing and Merging Branches
    • a simple merge is called a Fast Forward
    • to merge, checkout into target branch and exeucte 'git merge {source branch}'
  2. Understanding Git Diff
    • git diff <branchl> <branch2>
    • detailed explanation of diff output
  3. Using Git Diff
    • 'git diff' by itself only does unstaged files
    • 'git diff -cached' only diffs staged
    • 'git diff HEAD' both stagedand unstaged changes
    • 'dev/null' indicates a new file
    • 'git log --oneline' shows commit history
  4. Resolving Merge Conflicts
    • shows how to solve merge conflict
    • merge changes from parent frequently to avoid conflicts
  5. Aborting a Merge
    • you may want to abort a merge instead of fixing a conflict
Module 4: Using Git Branches with Your Team
  1. Setting up Remotes
    • shows how to fork and clone a repo
  2. Using Remotes with Code
    • explains difference between 'fit fetch' and 'git pull'
    • run 'git remote update' and then 'git status' to see changes to a remote
    • 'git pull' will do a fetch and merge
  3. Using Remotes with Branches
    • you don't always have to push to main, you can push your dev branch
      • git push -u origin feature4
    • 'git ls-remote' shows branched on remote
    • you have to use the 'track' flag for remote branches
      • git checkout --track origin/ feature4
  4. Using Pull Requests
    • pull request is not a feature of git
    • a demo of the pull request process on github
  5. Ignoring Files
    • .gitignore uses a regex like syntax
    • put .gitignore in root
    • to ignore files without using .gitignore, add it to '.git/info/excluse'
      • this will not get pushed to remote and will only apply locally
    • https://github.com/github/gitignore
      • A collection of useful .gitignore templates
  6. Setting Team Conventions
    • Frequent smaller commits vs. one giant commit
  7. Creating Code That Can Merge
    • Pick a formatting standard and stick to it
Module 5: Advanced Merging Methods
  1. Rearranging with Rebase
    • Rebase is an advanced feature
      • Not mandatory
      • It can cause problems
      • Do not rebase a public branch
    • you would use it to clean up your local history before sharing a branch
    • you would use it to pull changes from a branch into your branch without performing a merge
  2. Squashing Multiple Commits
    • rebase is squashing multiple commits into one
    • demo of using rebase to squash multiple commits into one
  3. Rebasing from Main
    • shows difference between git merge and git rebase
    • shows difference between "git pull" and "git pull --rebase"
  4. Using Cherry Pick
    • git cherry pick is when you take a specific commit and merge it, while merge brings all changes
    • Copy specific commits to another branch
      • Bugfix for multiple versions of product
      • Capture commits from inactive branch
    • Move specific commits to your branch
      • Features needed for your ticket
      • Branches not ready to merge yet
    • Creates duplicate commit in each branch
      • Can cause confusion
    • Cherry-pick is an advanced feature
      • Should not replace merge
  5. Cherry Pick Demos
  6. Conclusion

Comments

Popular posts from this blog

Angular Routing and Navigation Playbook

Working with Files in C# 10

Mastering Git