Ciò presuppone il telecomando "a monte" prende il nome "origine" e si ha la forchetta personalizzato sotto il tuo nome utente (ad esempio "maxandersen")
Quando hai il tuo clone di eseguire il seguente one liner (refresh Track all remote git branches as local branches:.
remote=origin ; for brname in `git branch -r | grep origin | grep -v master | grep -v HEAD | sed -e 's/.*\///g'`; do git branch --track $brname $remote/$brname ; done
questa configurazione di monitoraggio rami per tutti i rami presenti nel 'origine' nome remoto Se si dispone già di un checkout con questo branchname non lo farà cambia tutto tranne che assicurati che il tracciamento sia a posto.
(opzionale) Ora assicurare tutti i tuoi rami sono uptodate (utile se si dispone già rami controllato):
git pull --rebase --all
Ora, con tutti i setup rami per tracking e uptodate spinta rami e tag per il telecomando (sostituire 'maxandersen' con il tuo nome a distanza):
git push --all maxandersen
git push --tags maxandersen
Dopo questa forcella è in sincronia.
Il seguente script fa tutto questo tra cui chiedere conferma:
## Checkout all branches from remote as tracking branches. Based on https://stackoverflow.com/questions/379081/track-all-remote-git-branches-as-local-branches/6300386#6300386
UPSTREAM=$1
MYREPO=$2
usage() {
echo "Usage:"
echo "$0 <upstream-remote> <target-remote>"
echo ""
echo "Example which ensures remote named 'maxandersen' have all the same branches and tags as 'origin'"
echo "$0 origin maxandersen"
exit 1
}
if [ -z "$UPSTREAM" ]
then
echo Missing upstream remote name.
usage
fi
if [ -z "$MYREPO" ]
then
echo Missing target remote name.
usage
fi
read -p "1. This will setup '$MYREPO' to track all branches in '$UPSTREAM' - Are you sure ?" -n 1 -r
if [[ $REPLY =~ ^[Yy]$ ]]
then
for brname in `git branch -r | grep "$UPSTREAM" | grep -v master | grep -v HEAD | sed -e 's/.*\///g'`; do git branch --track $brname $UPSTREAM/$brname ; done
fi
read -p "2. This will push all local branches and tags into '$MYREPO' - Are you sure ?" -n 1 -r
if [[ $REPLY =~ ^[Yy]$ ]]
then
git push --all $MYREPO
git push --tags $MYREPO
fi
Salva come 'updateallbranchestags.sh' ed eseguirlo con:
sh updateallbranches.sh origin maxandersen
E tutti i rami/tag da 'origine 'sarà reso disponibile in remoto denominato' maxandersen '
fonte
2013-04-03 07:20:47
Suona un'implementazione concreta della mia risposta. +1 – VonC
Sì, nota che mi metto anche a usare --track invece di --set-upstream per sbarazzarmi di fastidiosi avvisi di deprecazione + Ho usato sed invece di awk per rendere l'oneliner ancora più corto :) Quindi grazie per i suggerimenti ! –
Non consiglierei --track per ragione spiegato nella mia risposta one-liner http://stackoverflow.com/a/6300386/6309 (aggiornato): dovresti usare '--set-upstream-to' (o' - u'), come spiegato in http://stackoverflow.com/a/10002469/6309 – VonC