Reputation: 2636
A colleague pushed a new remote branch to origin/dev/homepage and I cannot see it when I run:
$ git branch -r
I still see preexisting remote branches.
I assume this is because my local remote refs are not up-to-date hence when I ran a git pull nothing happened since git pull only pulls on the current working branch correct? Unlike git push which pushes all branches that have changes to the corresponding remote branch?
Upvotes: 208
Views: 332823
Reputation: 3017
Let's say we are searching for release/1.0.5
When git fetch --all
is not working and that you cannot see the remote branch and git branch -r
not show this specific branch.
1. Print all refs from remote (branches, tags, ...):
git ls-remote origin
Should show you remote branch you are searching for.
e51c80fc0e03abeb2379327d85ceca3ca7bc3ee5 refs/heads/fix/PROJECT-352
179b545ac9dab49f85cecb5aca0d85cec8fb152d refs/heads/fix/PROJECT-5
e850a29846ee1ecc9561f7717205c5f2d78a992b refs/heads/master
ab4539faa42777bf98fb8785cec654f46f858d2a refs/heads/release/1.0.5
dee135fb65685cec287c99b9d195d92441a60c2d refs/heads/release/1.0.4
36e385cec9b639560d1d8b093034ed16a402c855 refs/heads/release/1.0
d80c1a52012985cec2f191a660341d8b7dd91deb refs/tags/v1.0
The new branch release/1.0.5
appears in the output.
2. Force fetching a remote branch:
git fetch origin <name_branch>:<name_branch>
$ git fetch origin release/1.0.5:release/1.0.5
remote: Enumerating objects: 385, done.
remote: Counting objects: 100% (313/313), done.
remote: Compressing objects: 100% (160/160), done.
Receiving objects: 100% (231/231), 21.02 KiB | 1.05 MiB/s, done.
Resolving deltas: 100% (98/98), completed with 42 local objects.
From http://git.repo:8080/projects/projectX
* [new branch] release/1.0.5 -> release/1.0.5
Now you have also the refs locally, you can checkout (or whatever) this branch.
Job done!
Upvotes: 76
Reputation: 2265
The simplest answer is:
git fetch origin <branch_name>
Upvotes: 118
Reputation: 26
You can checkout remote branch /n git fetch && git checkout remotebranch
Upvotes: 0
Reputation: 3723
I used brute force and removed the remote and then added it
git remote rm <remote>
git remote add <url or ssh>
Upvotes: 6
Reputation: 23483
It sounds trivial, but my issue was that I wasn't in the right project. Make sure you are in the project you expect to be in; otherwise, you won't be able to pull down the correct branches.
Upvotes: 6
Reputation: 25451
Check whether .git/config
contains
[remote "origin"]
url = …
fetch = +refs/heads/master:refs/remotes/origin/master
If so, change it to say
[remote "origin"]
url = …
fetch = +refs/heads/*:refs/remotes/origin/*
Then you should be able to use it:
$ git fetch
remote: Counting objects: …
remote: Compressing objects: ..
Unpacking objects: …
remote: …
From …
* [new branch] branchname -> origin/branchname
$ git checkout branchname
Branch branchname set up to track remote branch branchname from origin.
Switched to a new branch 'branchname'
Upvotes: 187
Reputation: 30188
What ended up finally working for me was to add the remote repository name to the git fetch
command, like this:
git fetch core
Now you can see all of them like this:
git branch --all
Upvotes: 4
Reputation: 911
Doing a git remote update will also update the list of branches available from the remote repository.
If you are using TortoiseGit, as of version 1.8.3.0, you can do "Git -> Sync" and there will be a "Remote Update" button in the lower left of the window that appears. Click that. Then you should be able to do "Git -> Switch/Checkout" and have the new remote branch appear in the dropdown of branches you can select.
Upvotes: 34
Reputation: 8458
First, double check that the branch has been actually pushed remotely, by using the command git ls-remote origin
. If the new branch appears in the output, try and give the command git fetch
: it should download the branch references from the remote repository.
If your remote branch still does not appear, double check (in the ls-remote
output) what is the branch name on the remote and, specifically, if it begins with refs/heads/
. This is because, by default, the value of remote.<name>.fetch
is:
+refs/heads/*:refs/remotes/origin/*
so that only the remote references whose name starts with refs/heads/
will be mapped locally as remote-tracking references under refs/remotes/origin/
(i.e., they will become remote-tracking branches)
Upvotes: 258