Je veux être en mesure de faire ce qui suit :
Créer une branche locale basée sur une autre branche (distante ou locale) (via git branch
ou git checkout -b
)
Pousser la branche locale
vers le référentiel distant (publish), mais rendez-la
mais rendez-la traçable pour que git pull
et git push
fonctionnent immédiatement.
Comment puis-je faire cela ?
Je connais le --set-upstream
de Git 1.7, mais c'est une action post-création. Je veux trouver un moyen d'effectuer un changement similaire lors de la poussée de la branche vers le dépôt distant.
Avant l'introduction de git push -u
, il n'y avait pas d'option git push
pour obtenir ce que vous désirez. Vous deviez ajouter de nouvelles déclarations de configuration.
Si vous créez une nouvelle branche en utilisant :
$ git checkout -b branchB
$ git push origin branchB:branchB
Vous pouvez utiliser la commande git config
pour éviter de modifier directement le fichier .git/config
.
$ git config branch.branchB.remote origin
$ git config branch.branchB.merge refs/heads/branchB
Ou vous pouvez éditer manuellement le fichier .git/config
pour avoir des informations de suivi sur cette branche.
[branch "branchB"]
remote = origin
merge = refs/heads/branchB
Je suppose que vous avez déjà cloné un projet comme :
git clone http://github.com/myproject.git
Ensuite, dans votre copie locale, créez une nouvelle branche et vérifiez-la :
git checkout -b <newbranch>
Supposons que vous ayez fait un "git bare --init" ; sur votre serveur et créé le myapp.git, vous devriez :
git remote add origin ssh://example.com/var/git/myapp.git
git push origin master
Après cela, les utilisateurs devraient être en mesure de
git clone http://example.com/var/git/myapp.git
**REMARQUE : Je suppose que votre serveur est opérationnel. Si ce n'est pas le cas, cela ne fonctionnera pas. Vous trouverez un bon mode d'emploi [ici][1].
Ajouter une branche distante :
git push origin master:new_feature_name
Vérifier si tout est bon (récupérer l'origine et lister les branches distantes) :
git fetch origin
git branch -r
Créer une branche locale et suivre la branche distante :
git checkout -tb new_feature_name origin/new_feature_name
Mettez tout à jour :
git pull
[1] : http://toolmantim.com/thoughts/setting_up_a_new_remote_git_repository
edit Dépassé, utilisez simplement git push -u origin $BRANCHNAME
.
Utilisez git publish-branch
depuis William's miscellaneous Git tools (gitorious repo et clone).
OK, pas de Ruby, donc - en ignorant les protections ! - prenez les trois dernières lignes du script et créez un 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}
Ensuite, exécutez git-publish-branch REMOTENAME BRANCHNAME
, où REMOTENAME est habituellement origin (vous pouvez modifier le script pour prendre origin par défaut, etc...)