Adloun

Git : l'historique d'un projet (école d'ingénieur) · Chapitre 6 · Exercice de TD

Pousser vers un dépôt non nu

Les dépôts distants · niveau 2

Énoncé

Dans le clone a, Ada déclare comme distant le clone b (un dépôt ordinaire, où main est la branche courante), puis :


$ git push bureau main
Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
…
Total 3 (delta 0), reused 0 (delta 0), pack-reused 0 (from 0)
remote: error: refusing to update checked out branch: refs/heads/main
remote: error: By default, updating the current branch in a non-bare repository
remote: is denied, because it will make the index and work tree inconsistent
remote: with what you pushed, and will require 'git reset --hard' to match
remote: the work tree to HEAD.
remote: 
remote: You can set the 'receive.denyCurrentBranch' configuration variable
remote: to 'ignore' or 'warn' in the remote repository to allow pushing into
remote: its current branch; however, this is not recommended unless you
remote: arranged to update its work tree to match what you pushed in some
remote: other way.
remote: 
remote: To squelch this message and still keep the default behaviour, set
remote: 'receive.denyCurrentBranch' configuration variable to 'refuse'.
To ../b
 ! [remote rejected] main -> main (branch is currently checked out)
error: failed to push some refs to '../b'

Pourquoi b refuse-t-il ? Comment faire passer le commit de a à b sans rien changer à la configuration de b ?

Corrigé

b est un dépôt non nu, et main y est la branche courante : accepter l'envoi déplacerait main sans mettre à jour son répertoire de travail ni son index, qui ne correspondraient plus au commit de la branche. Git refuse (branch is currently checked out) et l'explique longuement dans les lignes remote:. La bonne direction est l'inverse : c'est b qui récupère chez a, par exemple avec git pull ../a main lancé dans b, ou mieux, les deux passent par le dépôt nu commun : a y envoie, b en récupère.

Exercices semblables

Le cours du chapitre · Tous les exercices du chapitre