Reputation: 3128
I have a remote branch feature/test2
. I want to fetch it. I run:
git fetch origin feature/test2
And I get:
From <URL>
* branch feature/test2 -> FETCH_HEAD
But when I run:
git for-each-ref --format='%(refname:short)' refs/remotes/origin/feature/test2
I don't see feature/test2
. Only if I run get fetch
, and then the command above, I'll see feature/test2
. Why is that?
Upvotes: 3
Views: 585
Reputation: 31
It lists all branches not merged into origin/release_15.0.0
git for-each-ref --no-merged=origin/release_15.0.0 --format="%(committerdate:short) %(authorname) %(refname:short)" --sort=committerdate **refs/remotes/origin**
It lists local branches not merged into origin/release_15.0.0
git for-each-ref --no-merged=origin/release_15.0.0 --format="%(committerdate:short) %(authorname) %(refname:short)" --sort=committerdate **refs/heads**
Upvotes: 1
Reputation: 21998
When you fetch a branch, git updates the corresponding ref in your local, which we call a remote-tracking branch. It mirrors the last known state of this remote ref.
You can see these branches with git branch -r
But these are not your local branches, which your for-each-ref
command asks for.
-- (The following assumes you're using a git version > 1.8.3) --
To create a local counterpart to your remote origin/feature/test2
, check it out
git checkout feature/test2
and git will recognize the name as one one your remote-tracking branches (since you already fetched it earlier) and set the link for push/pull operations.
At this point only will it appear in the output of your for-each-ref
command.
Upvotes: 2