Search code examples
gitgit-fetch

Shared origin has its master and HEAD at different commits


I have two local repos (say Repo1 and Repo2) which share the same remote repo (origin). I use this setup to share files between the two repos with the common origin as an intermediary (push from repo1 to origin, then pull from origin to repo2, etc.). Here are graphs of the commits from each repo:

Repo1:
* 6d2996f (HEAD, origin/master, origin/HEAD, master) minor changes
* ce12a68 minor changes
* 8faf9ab N=500
* c2edeec biserial results
* 8a788ba ready for biserial

Repo2:
* 6d2996f (HEAD, master) minor changes
* ce12a68 minor changes
* 8faf9ab N=500
* c2edeec (origin/master, origin/HEAD) biserial results
* 8a788ba ready for biserial

According to Repo1, origin's master and HEAD are at commit 6d2996f, while according to Repo2, origin's master and HEAD are at commit c2edeec. If its the same origin, how is this possible?


Solution

  • in repo2, you need to do

    git fetch
    

    (or git fetch origin) to get the information about the remote repo. This will update all origin/* refs.

    Git does not collect information about all remote repositories when you do git log or git status or something like that. You need to tell him when to fetch the information of the remote repository.

    Note that, when you do git pull, this always includes a git fetch.