Repasé otras preguntas similares extensamente antes de terminar haciendo mi propia pregunta sobre esto.
Estoy empezando a aprender Git y probé algo muy simple. Mi objective era crear un repository en mi máquina local, clonarlo en una carpeta en mi máquina local. Haga cambios a los files en el clon. Empuja los cambios al repository. Aquí esta lo que hice:
git init
dentro de la carpeta 'testing' git add .
git commit -m "done"
cd ..
git clone test newTest
Pude ver un nuevo clon de testing creado con una carpeta .git dentro y el hi.txt clonado desde el repository.
Luego hice cambios al hi.txt dentro del clon y ejecuté los siguientes commands:
git add .
git commit -m "done"
Hasta aquí todo bien. Ahora cuando trato de enviar los cambios a la carpeta repo 'test', aparece el siguiente error:
$ git push Counting objects: 5, done. Writing objects: 100% (3/3), 248 bytes, done. Total 3 (delta 0), reused 0 (delta 0) Unpacking objects: 100% (3/3), done. remote: error: refusing to update checked out branch: refs/heads/master remote: error: By default, updating the current branch in a non-bare repository remote: error: is denied, because it will make the index and work tree inconsist ent remote: error: with what you pushed, and will require 'git reset --hard' to matc h remote: error: the work tree to HEAD. remote: error: remote: error: You can set 'receive.denyCurrentBranch' configuration variable to remote: error: 'ignore' or 'warn' in the remote repository to allow pushing into remote: error: its current branch; however, this is not recommended unless you remote: error: arranged to update its work tree to match what you pushed in some remote: error: other way. remote: error: remote: error: To squelch this message and still keep the default behaviour, set remote: error: 'receive.denyCurrentBranch' configuration variable to 'refuse'. To c:/test ! [remote rejected] master -> master (branch is currently checked out) error: failed to push some refs to 'c:/test'
Entonces, ¿dónde me estoy equivocando? ¿He entendido mal algo? Estaré agradecido por tu ayuda.
El primer "repo" que ha creado se está comportando como una copy de trabajo, es decir, un repository no desnudo.
Los repositorys reales, a los que puede presionar, no tienen copy de trabajo en ellos. Solo mantienen una reference a todos los commits en todas las twigs.
Para convertir un repository normal en un repository simple
git config --bool core.bare true
Ahora puede presionar a su repository desnudo.
Editar: usando los pasos de su pregunta
mkdir test cd test git init echo '0.0.1' > version.txt git commit -a -m "version file"
Ahora tiene un repository no descubierto, con la estructura
Vamos a convertirlo en un repository simple
mv .git ../ rm * mv ../.git . mv .git/* . rm -rf .git git config --bool core.bare true
ahora tiene un repository simple, y su contenido es
si en algún momento obtiene el error fatal: This operation must be run in a work tree
simplemente ignórelo .
Ahora puedes clonarlo como originalmente lo hiciste
cd .. git clone test newTest touch index.html git commit index.html -m "index file" git push