If you are working on a feature branch and master keeps getting updates you will want to bring those changes into your branch. Doing this often avoids giant surprise conflicts on merge day and keeps CI from yelling at you. This guide shows the sane git commands to merge master into a branch while keeping your working tree tidy and your stress levels acceptable.
Short version first for the impatient humans. Then we will explain the drama in each step.
Change context to the branch that needs master updates. Replace feature-branch with your branch name.
git checkout feature-branch
# or the newer form
git switch feature-branch
Fetch remote changes and make sure your local master matches origin master. This ensures the merge brings the latest commits.
git fetch origin
git checkout master
git pull origin master
Go back to your branch and merge. If master can be fast forwarded there will be no merge commit. If not a merge commit will record the moment master landed in your branch.
git checkout feature-branch
git merge master
If you need a linear history consider rebasing instead of merging. Rebase rewrites commits and will cause trouble if the branch is shared with others. Use rebasing only when you know what you are doing.
If git reports conflicts run git status to see the files. Open each file, choose the correct code, then stage and finish the merge.
git status
# edit conflicted files
git add path/to/file
git commit
Pro tip If conflict resolution starts to look like therapy for code create a quick backup branch before you do anything drastic
git branch backup-feature-branch
git push origin feature-branch
Rebase moves your branch commits on top of master and gives a tidy linear history. Do not rebase commits that other people rely on. If your branch is private or you coordinate with reviewers rebase can be a nice option.
git checkout feature-branch
git rebase master
# resolve any rebase conflicts then
git rebase --continue
Merging master into a feature branch is a simple habit that prevents nasty surprises later. Keep your working tree clean backup if you are nervous and pick merge or rebase based on your team workflow. Do this often and your future self will thank you or at least not cry in the pull request comments.
I know how you can get Azure Certified, Google Cloud Certified and AWS Certified. It's a cool certification exam simulator site called certificationexams.pro. Check it out, and tell them Cameron sent ya!
This is a dedicated watch page for a single video.