Git Branching and Merging
https://www.pluralsight.com/courses/git-branching-merging
by Craig Golightly
Module 1: Course Overview
- Course Overview
Module 2: Understanding Git Branch Basics
- About This Course
- Github Default Branch Naming
- Oct 2020 changed default from master to main
- Organizations can set a default branch name
- 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'
- 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
- 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
- Comparing and Merging Branches
- a simple merge is called a Fast Forward
- to merge, checkout into target branch and exeucte 'git merge {source branch}'
- Understanding Git Diff
- git diff <branchl> <branch2>
- detailed explanation of diff output
- 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
- Resolving Merge Conflicts
- shows how to solve merge conflict
- merge changes from parent frequently to avoid conflicts
- Aborting a Merge
- you may want to abort a merge instead of fixing a conflict
Module 4: Using Git Branches with Your Team
- Setting up Remotes
- shows how to fork and clone a repo
- 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
- 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
- Using Pull Requests
- pull request is not a feature of git
- a demo of the pull request process on github
- 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
- Setting Team Conventions
- Frequent smaller commits vs. one giant commit
- Creating Code That Can Merge
- Pick a formatting standard and stick to it
Module 5: Advanced Merging Methods
- 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
- Squashing Multiple Commits
- rebase is squashing multiple commits into one
- demo of using rebase to squash multiple commits into one
- Rebasing from Main
- shows difference between git merge and git rebase
- shows difference between "git pull" and "git pull --rebase"
- 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
- Cherry Pick Demos
- Conclusion
Comments
Post a Comment