Git doesn't seem to want to keep local refs to origin/master

Go To StackoverFlow.com

7

First: apologies for the question title, I don't actually know what the problem is so I don't know how to ask about it.

I want to diff my master with upstream master (should be origin/master, based on the way my remotes are set up).

But: origin was put there after I had been working on it locally for a while, so it's "origin" in name only. That is: I had a local repo, put it up into a gitolite setup, and then told my local git to call it origin.

These are the symptoms:

$ git diff master orgin/master
fatal: ambiguous argument 'orgin/master': unknown revision or path not in the working tree.

$ git diff master origin/master --
fatal: bad revision 'origin/master'

Hm.

$ git remote -v
origin  git@example.com:example (fetch)
origin  git@example.com:example (push)

okay, that looks right.

$ git branch -a
... # nothing from origin

Hm.

$ git fetch -a origin
From example.com:example
* branch            HEAD       -> FETCH_HEAD

I have no idea if that's correct. It looks productive, but git diff master origin/master still fails, and:

$ git branch --track omaster origin/master
fatal: Not a valid object name: 'origin/master'.

Wha?

$ ls .git/refs/remotes
gitps  ps

That looks wrong: those are old remotes that haven't existed for months. Also they're empty. And .git/remotes doesn't exist at all, although I'm not sure that it should.

2012-04-03 21:16
by quodlibetor


10

You may need to tell git which branches to fetch from origin. In the .git/config file for this repo, under the [remote "origin"] section, there should be a line like fetch = .... This tells git what to fetch and where to put it locally. Here's a pretty standard example:

[remote "origin"]
        fetch = +refs/heads/*:refs/remotes/origin/*
        url = ssh://...

If you don't see the fetch = ... line, you can safely add it to match the example, which is the standard "track all branches and call them origin/branch locally" option set up by git clone.

See the git pro book for a good description of what's going on.

2012-04-03 21:34
by chazomaticus
Awesome, thank! Yeah, the fetch line was missing completely - quodlibetor 2012-04-03 21:36
Thanks. For me, my fetch line existed, but was only fetching from a particular release branch for some reason. I updated the line to the above and did git remote update and then git reset --hard origin/branchname and everything works perfectly - Phil 2016-10-12 11:21


11

Have you tried git remote update? This will update all remotes, creating remote-tracking branches as needed.

2012-04-03 21:22
by Lily Ballard
Just tried it, exactly the same result as git fetch -a origin, unfortunately - quodlibetor 2012-04-03 21:34


0

I had a similar issue just now. I discovered that my local .git directory as actually a file

$ file .git
     .git: ASCII text

I deleted the file, and initialized the git repository

git init && git remote add origin "gitrepo"

Not too sure why this happened. Hopefully this can help someone..

2017-06-19 14:06
by Begui