Voglio essere in grado di fare quanto segue:
Creare un ramo locale basato su qualche altro ramo (remoto o locale) (tramite git branch
o git checkout -b
)
Spingere il ramo locale
al repository remoto (publish), ma rendilo
tracciabile in modo che git pull
e git push
funzionino immediatamente.
Come faccio?
So di --set-upstream
in Git 1.7, ma è un'azione post-creazione. Voglio trovare un modo per fare un cambiamento simile quando si spinge il ramo al repository remoto.
Prima dell'introduzione di git push -u
, non c'era un'opzione git push
per ottenere ciò che si desidera. Dovevi aggiungere nuove dichiarazioni di configurazione.
Se si crea un nuovo ramo usando:
$ git checkout -b branchB
$ git push origin branchB:branchB
Puoi usare il comando git config
per evitare di modificare direttamente il file .git/config
.
$ git config branch.branchB.remote origin
$ git config branch.branchB.merge refs/heads/branchB
Oppure puoi modificare manualmente il file .git/config
per avere informazioni di tracciamento su questo ramo.
[branch "branchB"]
remote = origin
merge = refs/heads/branchB
Suppongo che abbiate già clonato un progetto come:
git clone http://github.com/myproject.git
Poi nella tua copia locale, crea un nuovo ramo e controllalo:
git checkout -b <newbranch>
Supponendo che tu abbia fatto un "git bare --init" sul tuo server e creato il myapp.git, dovresti:
git remote add origin ssh://example.com/var/git/myapp.git
git push origin master
Dopo questo, gli utenti dovrebbero essere in grado di
git clone http://example.com/var/git/myapp.git
NOTA: Sto assumendo che tu abbia il tuo server attivo e funzionante. Se non lo è, non funzionerà. Un buon how-to è qui.
AGGIUNGI
Aggiungere un ramo remoto:
git push origin master:new_feature_name
Controlla se tutto è a posto (recupera l'origine e elenca i rami remoti):
git fetch origin
git branch -r
Crea un ramo locale e traccia il ramo remoto:
git checkout -tb new_feature_name origin/new_feature_name
Aggiorna tutto:
git pull
edit Superato, basta usare git push -u origin $BRANCHNAME
.
Usare git publish-branch
da William's miscellaneous Git tools (gitorious repo e clone).
OK, niente Ruby, quindi - ignorando le protezioni! - prendete le ultime tre righe dello script e create uno script bash, git-publish-branch
:
#!/bin/bash
REMOTE=$1 # Rewrite this to make it optional...
BRANCH=$2
# Uncomment the following line to create BRANCH locally first
#git checkout -b ${BRANCH}
git push ${ORIGIN} ${BRANCH}:refs/heads/${BRANCH} &&
git config branch.${BRANCH}.remote ${REMOTE} &&
git config branch.${BRANCH}.merge refs/heads/${BRANCH}
Poi esegui git-publish-branch REMOTENAME BRANCHNAME
, dove REMOTENAME è solitamente origin (puoi modificare lo script per prendere origin come default, ecc...)