I want to do some things for each branch which fits to a given criteria.
Example:
Track all branches from a specific remote:
For each branch I simply have to: git checkout --track remotes/origin/br1
But if I now want to do this as a bulk change, I have to write something like:
git branch --all| grep 'remotes/origin' | xargs -n1 git checkout --track
But this will fail for some of the found "branches" because they are not branches but symbolic-refs like remotes/origin/HEAD
which points to origin/master
.
As I read from other answers like https://stackoverflow.com/a/3099621/878532 I see that the people are manually filtering out wrong refs with "grep -v HEAD" here. But this is not what I expect, because here I have to know that HEAD is a symbolic-ref and not a branch.
So I need something to find only real branches. I already take a look on git for-each-ref --format <...>
and was in hope that objtype
give me some hint but I did not get anything which helps.
Q: How I can get a list of real branches to use them for a bulk change.