Is there a simple way to sync current branch with remote master
?
I use next commands to do that (from local branch develop
):
git checkout master
git pull
git checkout develop
git merge master
Is there a simple way to sync current branch with remote master
?
I use next commands to do that (from local branch develop
):
git checkout master
git pull
git checkout develop
git merge master
Your process does the job and doesn't seem that long to type, but you could always speed up the process by setting an alias, like
git config --global alias.whatever '!git checkout master && git pull && git checkout develop && git merge master'
# then to use it just type
git whatever
You don't actually need to checkout a branch to sync it*, so instead of the first checkout
and pull
you can just run git fetch origin master:master
.
So now you just have a fetch
and a merge
, but wait if you read the first part of the git pull
documentation you learn that a pull
is just a fetch
, then a merge
.
So in reality all you have to do is a special git pull
: git pull origin master:master
.
It'll get changes from origin master and merge them into your current branch.
master:master
means to pull the changes from master down to your current branch, but to also update your own copy of master (the first master is what you are pulling, the second is to update your own master at the same time)
Main benefits of this way, other than being 1 command, is you avoid doing 2 checkouts which are slow. Downside is it will not work if there is any conflicts between between your master and origin's.
*If it is a fast forward update, that is you've done no work on it.