gitgithubbitbucket

Does git checkout branch command actually really compare against remote?


My project currently have two branch, master and feature, and I working on feature branch.

When I'm done, I have performed git push to bitbucket and perform pull request at bitbucket dashboard.

Now that everything has done, I head back to my terminal, I am still at feature branch, so what I do is git checkout master to switch back to master, and I get the message

Switched to branch 'master'

Your branch is up to date with 'origin/master'

I thought this means that my local workspace is actually updated and synced with remote origin, but then it's wrong because I ran git pull and I get below

remote: Counting objects: 1, done.
remote: Total 1 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (1/1), done.
From https://git.domain.com:1234/bitbucket/xx/xx
   256c6bc..0a3bb4f  master    -> origin/master
Updating 256c6bc..0a3bb4f
Fast-forward
 .eslintrc.js                  |  15 +-
 App/Containers/xx.js | 363 ++++++++++++++++++------------------
 App/Containers/xxa.js  | 594 +++++++++++++++++------------------------------------------
 3 files changed, 352 insertions(+), 620 deletions(-)

At this point I kinda think there's no magic and master branch will not magically being the same as remote origin, and hence I will need to git pull.

  1. Wondering if my understanding is correct?
  2. At the earlier stage, when I first switched back to master after performing the merge, isn't the message Your branch is up to date with 'origin/master' kinda misleading?

Solution

  • The key part is that in git there are really 3 "copies" of any branch:

    1. The copy on the local machine
    2. The copy of the remote on the local machine
    3. The copy on the remote machine

    When git status tells you "Your branch is up to date with 'origin/master'", it is comparing #1 and #2. Performing git fetch is how #2 is updated to match #3.

    In short, you're correct that there is no magic. On your machine origin/master is not automatically kept up-to-date with the actual remote.