Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can Git fetch from remote-tracking branches of a remote repository?

Tags:

git

Typically the source of git fetch is ref/heads/* of the remote repository.

Is it not allowed to fetch from remote-tracking branches i.e. ref/remotes/* of the remote repository?

like image 957
Tim Avatar asked Dec 31 '15 17:12

Tim


1 Answers

Of course!

A "normal" fetch is git fetch origin refs/heads/*:refs/remotes/origin/*

This is telling the current repository to connect to origin, get a list of refs/heads/* and store the references in the local refs/remotes/origin/.

You can tweak this to get the origin:refs/remotes/* like so: git fetch origin refs/remotes/*:refs/remotes/origin/*

It's worth noting that the usefulness of this depends on your knowledge of the remote you're talking to: You get the remote name that was configured in the remote you're referencing, but you don't get the details about that remote. In other words you could well end up seeing a new entry refs/remotes/origin/origin/master but what exactly that's tracking would be a mystery unless you know what origin/origin really is.

like image 69
Guildencrantz Avatar answered Sep 27 '22 21:09

Guildencrantz