The point of this gist is to give you helpful info on some ways that you can update a feature branch
you are working on to the current master/main
, if you get behind master/main
branch. The idea behind this is that when you try to merge your branch you have (hopefully) have less merge conflicts. The two ways I'll outline here are done via the following:
- Fast Forward Merging
- Rebasing
This is the way most devs learn how to merge the current master/main branch into your working branch.
First you need to make sure your local master/main
branch is up to date. Go to your local project and check out the branch you want to merge into (your local master/main
branch)
$ git checkout master
Fetch the remote, doing this will bring the current master
/main
branch and their commits from the remote repository. You can use the -p
, --prune
option to delete any remote-tracking references that no longer exist in the remote. Commits to master will be stored in a local branch, remotes/origin/master
$ git pull
This will do a git fetch
and a git merge
. Merge the changes from origin/master
into your local master branch. This brings your master branch in sync with the remote repository without losing your local changes. If your local branch didn't have any unique commits, Git will instead perform a "fast-forward".
$ git checkout <feature-branch>
Merge your (now updated) master branch into your feature branch to update it with the latest changes from your team.
$ git merge master
Depending on your git configuration this may open vim. Enter a commit message, save, and quit vim:
Press a
or i
to enter insert mode and append the text following the current cursor position.
Press the esc
key to exit insert mode and enter command mode.
Type :wq
or :x
to write the file to disk and quit.
This only updates your local feature branch. To update it on GitHub, push your changes.
$ git push origin <feature-branch>.