git branch - Git shortcut for checkout, pull, checkout, merge/rebase -
let's i've got 2 branches, master , codydev. before begin making changes on codydev, following in order make sure i'm starting latest master commit on codydev:
git checkout master
git pull
git checkout codydev
if changes, git merge master
is there shortcut first 3 steps, don't have leave codydev branch? tend find out master has not been updated , checkout/pull/checkout 3 unnecessary commands.
note did google try find answer question, there seems wide range of potential , complicated solutions. 1 seemed appealing affect of git fetch origin master:master
, explanations read not super clear because examples bit more complicated. found myself wondering "why fetch instead of pull" (i.e. git pull origin master:master
)?
you can update codydev
branch latest changes master
without changing branches:
git checkout codydev # ignore if on codydev git fetch origin # updates tracking branches, including origin/master git merge origin/master # merge latest master codydev
the trick here merge latest master
codydev
don't need update local master
branch. instead, can update remote tracking branch origin/master
(via git fetch
) , merge instead.
you can directly update local master
branch using git fetch
without checking out local master
branch:
# branch codydev git fetch origin master:master
however, work if merge fast-forward of local master
branch. if merge not fast-forward, not work, because working directory required in case merge conflicts arise.
read here more information.
Comments
Post a Comment