0

I have a personal git repo on a server ("Server Repo"). It cannot see a branch on its central remote repo ("Origin") that I pushed from a personal git repo on another computer ("Personal Repo").

Server Repo (personal repository):

$ git branch -a
* master  
remotes/origin/master

Origin (central repository):

$ git branch -a
* master  
update

Personal Repo (personal repository):

$ git branch -a
* update  
master  
remotes/origin/HEAD -> origin/master  
remotes/origin/master  
remotes/origin/update  

On Server Repo, I've tried $ git fetch --all but all I get is Fetching origin with no results.

$ git fetch -v --all yields:

Fetching origin
 = [up to date] master -> origin/master

I've never seen this issue before. I'm having a lot of issues searching for this problem because all Git Fetch issues seem to assume that the user is doing something wrong. As far as I can tell, Git is failing to recognize remote branches and I don't know what to do about it.

I've re-cloned from Origin into a new folder and the branches appear as expected then. I'm not sure what it is about re-cloning a repo from Origin that would get it to work properly. I have verified that in Server Repo the remote Origin is in fact correct and has the correct path (it's an absolute path on the same machine).

2 Answers2

0
git checkout --track origin/update
Dušan Maďar
  • 9,269
  • 5
  • 49
  • 64
  • This unfortunately did not work. I got the following error: `fatal: git checkout: updating paths is incompatible with switching branches. Did you intend to checkout 'origin/update' which can not be resolved as commit?` – neveraskedforthis Jul 07 '15 at 21:42
0

The syntax in this answer worked: https://stackoverflow.com/a/1614996/448640

$ git fetch origin remote_branch_name:local_branch_name

This doesn't answer why I couldn't use the normal command to fetch, but at least it solved the problem.

After performing this version of the command, I have the Origin update branch locally on Server Repo, but when I run git branch -a I still don't see remotes/origin/update. Still confused.

UPDATE 1:
Andrew C suggested that I look at my fetch specifications in <repo>/.git/config on Server Repo. I searched and found an example in the Git docs of what that specification is supposed to be: https://git-scm.com/book/en/v2/Git-Internals-The-Refspec

My Server Repo config file looked like this before:

[core]
    repositoryformatversion = 0
    filemode = true
    bare = false
    logallrefupdates = true
[remote "origin"]
    url = /home/user/repo/project.git
    fetch = +refs/heads/master:refs/remotes/origin/master
[branch "master"]
    remote = origin
    merge = refs/heads/master

Note the line with fetch = +refs/heads/master:refs/remotes/origin/master. The link to git-scm.com has an example with wildcards like this: fetch = +refs/heads/*:refs/remotes/origin/*

So I changed master to * in my fetch directive and now I can see and fetch my branches like normal!

$ git branch -a
  update
* master
  remotes/origin/master

$ git fetch
From /home/user/repo/project.git
 * [new branch]      update -> origin/update

$ git branch -a
  update
* master
  remotes/origin/update
  remotes/origin/master

I'm not sure why the fetch spec was incorrect, but I've now answered the question of why I couldn't see my remote branches, and I've solved the problem of obtaining the remote branches.

Please correct me if I'm wrong, but I am going to guess that because the fetch spec only specified the master branch, it was ignoring all other branches. The : notation command I used to get the remote branch must ignore the fetch spec in the config file.

Community
  • 1
  • 1