Can't see remote branch, problems with .git/co

2019-02-19 05:13发布

问题:

For some reason I can't see new branches that one my team has entered, I am 99% sure the branch exists as I can see it in Bitbucket's UI.

I have a feeling it may be because my .git/config file is not correct.

At the moment I have this...

[remote "origin"]
    url = git@bitbucket.org:user/project.git
    fetch = +refs/heads/master:refs/remotes/origin/master
    fetch = +refs/heads/testing:refs/remotes/origin/testing
    fetch = +refs/heads/uat:refs/remotes/origin/uat
    fetch = +refs/heads/release-1.9:refs/remotes/origin/release-1.9

I have tried "git remote update" & "git fetch origin" but both fail to get the new branch

I remember "starring" the issue here I can't see my remote branch, and changing my config to something like the following on an older laptop

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

I would really like to know the underlying reason as to why my config file is in it's current state...perhaps I am not creating branches in the correct way?

In general when creating new branches I am doing something like

git checkout -b issue-1001

And then the following to share my branch

git push origin issue-1001

回答1:

The fetch refspec you have in place is only fetching master, testing, uat, and release-1.9. As a result, any other branches pushed up to the remote repo, are ignored and are never brought to your local repo. The refspec on your laptop:

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

says to fetch all branches from the remote repository, so any new branches would be visible to you.

The short form is that if you want to see the new branches, then you need to use a refspec like the one above.

BTW, the way you're creating branches looks fine. :-)