简体   繁体   中英

Fetching all remote branches into a bare Git repository

I set up a Github post-receive hook, which runs a script on my web server whenever a push is made to my Github repository.

When the script runs, I want it to keep a local bare clone of the repository synchronized with my Github repository. To do this, I have it run this command:

git fetch origin && git reset --soft refs/remotes/origin/master

Then, if from my workstation I push to master on Github, everything works just fine. However, if I push to another remote branch, the changes are not reflected in my server's local bare repository.

I'm assuming there's some way to have the script fetch all of the remote branches, but I don't know how to do this. I know newer versions of git have a --all option for fetch/pull, but I'm using git version 1.6.3.3, which doesn't seem to have this option.

Does anyone know how I can get my script to fetch all remote branches?

Thanks!

git fetch origin '*:*'为我工作。

Use a shell script perhaps?

#!/bin/sh

for i in `git remote show`; do
    git fetch $i;
done;

Note: Small terminology error in your question: The --all option of git fetch|pull fetches all "remotes", not "remote branches".

Figured I'd provide my own solution while I'm at it. I accepted Ramkumar's though, as it was the inspiration for this. The difference is I don't want to fetch from all remotes, but rather each remote branch in "origin"...


#!/bin/bash
REMOTE_BRANCHES=$(git branch -r | awk -F'/' '{print $2}')
for i in $REMOTE_BRANCHES; do
    git fetch origin $i
done

DISCLAIMER: haven't really implemented this yet, but it should be close.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM