Tengo una carpeta con las fuentes de mi proyecto. Cómo puedo empujar este proyecto en Github's repositorio?
He intentado utilizar estos pasos:
git init
, así que dentro de la raíz del proyecto apareció la carpeta .git
.git add sourcesFolderName
.git commit -m "confirmación inicial"
.git remote add MyProject <url>
.git push
, pero no se envía nada al repositorio remoto... (no hay fallo de autorización)Entonces, ¿cómo puedo empujar fuentes existentes en repo github de nueva creación?
git init
git add .
git commit -m "Initial commit"
git remote add origin <project url>
git push -f origin master
La opción -f
en git push
fuerza el push. Si no la usas, verás un error como este:
To [email protected]:roseperrone/project.git
! [rejected] master -> master (fetch first)
error: failed to push some refs to '[email protected]:roseperrone/project.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first merge the remote changes (e.g.,
hint: 'git pull') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
tendrás que especificar qué rama y qué remoto al hacer el push:
➤ git init ./
➤ git add Readme.md
➤ git commit -m "Initial Commit"
➤ git remote add github <project url>
➤ git push github master
Funcionará como se espera.
Puede configurar esto por defecto haciendo:
➤ git branch -u github/master master
que te permitirá hacer un git push
desde master sin especificar el remoto o la rama.
Si tienes un Mac (y probablemente funcione igual en un PC), aquí tienes una forma muy sencilla de hacerlo. Por extraño que parezca I'he mirado alto y bajo para este sencillo proceso y nunca lo encontré.
Sé que no es recomendable utilizar la carpeta del proyecto como la carpeta repo. Yo lo hago todo el tiempo, siempre funciona, lo hace simple, y nunca tengo ningún problema con él.