Let's say I've got 2 branches, master and codyDev. Before I begin making changes on codyDev, I do the following in order to make sure I'm starting from the latest master commit on codyDev:
git checkout master
git checkout codyDev
git merge master
git fetch origin master:master
git pull origin master:master
You can update your
codyDev branch with the latest changes from
master without actually changing branches:
git checkout codyDev # ignore if already on codyDev git fetch origin # updates tracking branches, including origin/master git merge origin/master # merge latest master into codyDev
The trick here is that to merge the latest
codyDev you don't actually need to update your local
master branch. Instead, you can just update the remote tracking branch
git fetch) and then merge it instead.
You can also directly update the local
master branch using
git fetch without actually checking out the local
# from branch codyDev git fetch origin master:master
However, this will only work if the merge is a fast-forward of the local
master branch. If the merge be not a fast-forward, then this will not work, because a working directory is required in case merge conflicts arise.
Read here for more information.