[git] Remote branch is not showing up in "git branch -r"

I have been pushing to a remote Bitbucket repository and recently a colleague has pushed a new branch he created to the same repository.

I'm trying to fetch the changes he uploaded.

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

$ git branch -r origin/master

In the web UI for Bitbucket I can see the branch he has made. How can I do this?

Next try:

$ git fetch bitbucket
Password for 'https://[email protected]':
From https://bitbucket.org/user/repo
 * branch            HEAD       -> FETCH_HEAD

If the branch he created is called new_branch_b should I be expecting to see the following?

$ git branch -r
origin/master
origin/new_branch_b

Third try:

$ git remote update
Fetching bitbucket
Password for 'https://[email protected]':
From https://bitbucket.org/user/repo
 * branch            HEAD       -> FETCH_HEAD

$ git branch -r
  origin/master

Fourth try:

[remote "bitbucket"]
url = https://[email protected]/user/repo.git

I called the remote bitbucket rather than origin (at least that's what I recall; I set it up a while ago)

Fifth try:

I updated the Bitbucket remote configuration as per kan's answer:

$ git config -e

[remote "bitbucket"]
    url = https://[email protected]/user/repo.git
    fetch = +refs/heads/*:refs/remotes/bitbucket/*

For most people it will be called origin:

[remote "origin"]
    url = https://[email protected]/user/repo.git
    fetch = +refs/heads/*:refs/remotes/origin/*

Afterwards,

$ git remote update

Fetching bitbucket
Password for 'https://[email protected]':
remote: Counting objects: 48, done.
remote: Compressing objects: 100% (32/32), done.
remote: Total 35 (delta 21), reused 0 (delta 0)
Unpacking objects: 100% (35/35), done.
From https://bitbucket.org/user/repo
 * [new branch]      branch_name1 -> origin/branch_name1
 * [new branch]      branch_name2    -> origin/branch_name2

.... and so on.

I think git fetch origin would also work for git remote update.

This question is related to git

The answer is


If you clone with the --depth parameter, it sets .git/config not to fetch all branches, but only master.

You can simply omit the parameter or update the configuration file from

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

to

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

I had the same issue. It seems the easiest solution is to just remove the remote, readd it, and fetch.


Unfortunately, git branch -a and git branch -r do not show you all remote branches, if you haven't executed a "git fetch".

git remote show origin works consistently all the time. Also git show-ref shows all references in the Git repository. However, it works just like the git branch command.


Update your remote if you still haven't done so:

$ git remote update
$ git branch -r