Git Update Local Branch with remote Master
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