2

Using git bash: I worked on my master branch, pushed it and decided I want to implement a new feature. I created a new branch for that. Later I added another feature, creating yet another branch.

I tested everything and it was working, so I decided to merge everything to my master branch. I pushed both new branches to the remote repo.

Now, using my browser github suggested to create pull requests for the new branches, which I did, and then suggested that I can safely merge, as there are no conflicts. So I merged all branches to master.

I thought, that since I did this online, my local branch would not be up to date anymore.

$ git status
On branch master
Your branch is up to date with 'origin/master'.

nothing to commit, working tree clean

I couldn't really believe that, so I decided to pull from my remote repo.

$ git pull origin master
remote: Enumerating objects: 2, done.
remote: Counting objects: 100% (2/2), done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 2 (delta 0), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (2/2), done.
From https://github.com/name/repo
 * branch            master     -> FETCH_HEAD
   ID..ID  master     -> origin/master
Updating ID..ID
Fast-forward
 file1 |  67 +++--
 file2     |  25 ++
 file3        | 292 +++++++++++----------
 3 files changed, 221 insertions(+), 163 deletions(-)
 create mode 100644 newfile

Why did git think my local master branch was up to date, when in fact it wasn't?

Disclaimer: I'm not very experienced with git and work soley on my repos.

idkfa
  • 159
  • 6

2 Answers2

4

After the work you did via Github, you would have needed to run git fetch to refresh the information about your remote-tracking branches and see any updates to git status.

git pull, in simple terms, is just doing git fetch and git merge.

This SO question is full of great info about this.

cody
  • 10,354
  • 3
  • 17
  • 31
  • Also branch `origin/master` is only a local copy of remote and is updated only by fetching changes directly or indirectly. – mx0 Dec 16 '18 at 13:39
2

When you did your git status, git compared your local master branch with the local copy of remote master branch. This can be confusing at first but is in fact quite simple.

Your local repo keeps copies of the remote repo references, so git status does not involve any network activity, it's an entirely local operation.

To update these local copies of remote branches, you need to git fetch, or git pull, like you did, which is using git fetch internally anyway.

Only at this point does your local repo get the updated version of your online actions (your pull requests).

RomainValeri
  • 14,254
  • 2
  • 22
  • 39