I often need to checkout latest version of another branch:
git checkout anotherbranch
git pull
How can I do that without checking out outdated version of anotherbranch first?
e.g.:
GIVEN
WHEN:
THEN:
How do I checkout latest version of master?
Does following the trick?
git fetch origin master
git checkout master
One way I deal with this general situation is to work with the remote tracking branch origin/master
, rather than working with the local master
branch. Let's say that you wanted to merge the latest remote master
into feature1
from the feature1
branch. You could achieve that by using:
# from feature1
git fetch origin
git merge origin/master
The git fetch
trick above will update all of your remote tracking branches, such that the local origin/master
will now reflect whatever latest changes are on the Git repository. You can then use origin/master
for whatever purpose you might have.
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