Ian Jamieson
Ian Jamieson

Reputation: 4826

GIT isn't fetching my new branch

I have created a new branch on my remote, so I would expect to do this:

$ git fetch && git checkout feature/name

However, I get this error:

error: pathspec 'feature/name' did not match any file(s) known to git.

When I run git fetch on its own, it doesn't return anything, I have also tried git fetch origin which does not work either.

git remote returns just the one remote called origin.

My config looks like this:

[core]
    repositoryformatversion = 0
    filemode = true
    bare = false
    logallrefupdates = true
    ignorecase = true
    precomposeunicode = true
[remote "origin"]
    url = removed as it is a private repo
    fetch = +refs/heads/staging:refs/remotes/origin/staging
[branch "staging"]
    remote = origin
    merge = refs/heads/staging

Upvotes: 1

Views: 562

Answers (3)

kenorb
kenorb

Reputation: 166871

The fix is to correct your remote.origin.fetch parameter, e.g.

git config remote.origin.fetch '+refs/heads/*:refs/remotes/origin/*'

so all branches can be fetched. See: How to fetch all remote branches?

Upvotes: 2

Ian Jamieson
Ian Jamieson

Reputation: 4826

As per Andrew C's comment. I changed the fetch line in my git config to this:

fetch=+refs/heads/*:refs/remotes/origin/*

Upvotes: 1

CodeWizard
CodeWizard

Reputation: 142622

If you are on GIt >1.9.X you have a default upstream with the value of simple.

If you want to get all the branches and tags you should use: git fetch --all --prune
--all will fetch all the branches and tags
--prune will delete all the deleted branches and tags

The flags will apply on your local repository.

Upvotes: 0

Related Questions