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

Git

Git Problem Overview


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://user@bitbucket.org/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.

Git Solutions


Solution 1 - Git

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

$ git remote update
$ git branch -r

Solution 2 - Git

The remote section also specifies fetch rules. You could add something like this into it to fetch all branches from the remote:

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

(Or replace origin with bitbucket.)

Please read about it here: 10.5 Git Internals - The Refspec

Solution 3 - Git

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/*

Solution 4 - Git

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

Solution 5 - Git

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionfeargalView Question on Stackoverflow
Solution 1 - GitB BrendlerView Answer on Stackoverflow
Solution 2 - GitkanView Answer on Stackoverflow
Solution 3 - GitDonPaulieView Answer on Stackoverflow
Solution 4 - GitjessicahView Answer on Stackoverflow
Solution 5 - GitThushanView Answer on Stackoverflow