Skip to content

Error: Reference 'refs/remotes/user/foo/HEAD' not found #523

Closed

Description

@vasiliyb

Folks, I have a branch called user/foo that I'd like to check out from remote. Code:

Git.prototype.refresh = function refresh(branch) {
    var repository;

    var options = {
        credentials: function() {
            return NodeGit.Cred.userpassPlaintextNew(GITHUB_TOKEN, "x-oauth-basic");
        },
        certificateCheck: function() {
            return 1;
        }
    };

    return NodeGit.Repository.open(localPath).then(function (repo) {
        repository = repo;

        return repository.checkoutBranch(branch, options).then(function (checkoutresult) {

            return repository.fetchAll(options).then(function (result) {
                return Promise.resolve(result);
            }).catch(function (err) {
                console.log('Unable to fetch',err);
                return Promise.reject(new Error(err));
            });
        }).catch(function(err) {
            console.log('checkoutBranch',err);
            return Promise.reject(new Error(err));
        });
    });
};

error:

[Error: Error: Reference 'refs/remotes/user/foo/HEAD' not found]

Am I using checkoutBranch incorrectly? I already have the remote cloned to a local directory, and am trying to switch to a particular branch.

Thanks!

Activity

  1. johnhaley81 commented on Apr 1, 2015

    @johnhaley81
    Collaborator

    I saw your post on Stack Overflow as well. I'll try to answer what you have here and then copy the resolution over to that question.

    So you can only checkout a local branch. You're trying to checkout a remote. What you'll have to do is get the commit on the remote branch and then use that to create a new branch and then (optionally) set the upstream to track the original remote branch.

    At that point you can then check out your newly created local branch.

    We're pretty active over on our gitter so if you're still having problems swing by and we'll see what we can do to help.

  2. vasiliyb commented on Apr 1, 2015

    @vasiliyb
    Author

    GREAT! thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions