I see two possibilities of doing this:
Do a replace of the local branch with the changes from remote master
Follow the work flow that I get using Gitlab by creating a merge request and merge the changes from master branch into the branch that I wish to update to the latest from master
What are the advantages and disadvantages of both these approaches? I'm leaning more towards the first approach. What do you guys say?
In GitHub Desktop, click Current Branch. Click Choose a branch to merge into BRANCH. Click the branch you want to merge into the current branch, then click Merge BRANCH into BRANCH. Note: If there are merge conflicts, GitHub Desktop will warn you above the Merge BRANCH into BRANCH button.
The simple answer - there are plenty of more complicated ones - is to just do a merge, so:
git checkout master
git pull
git checkout <your-branch>
git merge master
(This is effectively the same as you describe in option 2)
Depending on your settings, you might not need all of those steps (but doing them all won't hurt) - I'd recommend reading up on each of the commands to find the precise workflow that fits you best.
This will merge the changes from master into your branch and probably create a new commit, with a comment making it clear that it's a merge.
The alternative, and slightly more advanced option would be to rebase
, instead of merge
, which will effectively rewind time to the point at which your branch diverged from master, then pull in the changes on master, bringing your branch in-line with master, but without your commits, and finally apply your commits at the end. The advantage of this is that it keeps the history more simple - you just get a straight line of changes, with the changes from your branch right at the end, rather than two separate branches that join at the point of the merge.
To do that, you'd do:
git checkout <your-branch>
git rebase master
I'd recommend reading the docs on rebase, because there are lots of cases where it gets difficult, and if you're new to git, definitely go for merge, but come back to rebase when you're more confident - it's a very powerful feature, and more like what I think you're describing in your option 1.
If you remote
is set to the default origin
, (you can check it by using git remote -v
), you could just do:
git merge origin master
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With