I didn't find a simple solution but this one works for me:
git branch -ar | sed 's|^[ \t]*||' | grep -e '^alice/' | sed 's|alice/||' | xargs git fetch alice
Explanation:
- list remote branches
- remove leading whitespace produced by git branch
- only keep branches starting from "alice/", and remove that prefix from each branch name
- pass the names of the branches to
git fetch
Or, as a general bash function that can be added to your .bashrc
:
# Usage:
# git-sync-remote <remote-name>
# Example:
# git-sync-remote alice
git-sync-remote(){
REMOTE_NAME="$1"
if [ -z "${REMOTE_NAME}" ] ; then
echo 'You need to provide remote name'
return
fi
git branch -ar | sed 's|^[ \t]*||' | grep -e "^${REMOTE_NAME}/" | sed "s|${REMOTE_NAME}/||" | xargs git fetch "${REMOTE_NAME}"
}