Comandos utiles de GIT v.1 16/08/2024
Ver la configuracion del git:
git config --list
Ver donde estan las configuracion guardadas del git:
git config --list --show-origin
Agregar el name y email a la confuguracion del git:
git config --global user.name "Giovedy Marmolejo"
git config --global user.email "[email protected] "
CAmbiar de master a main la rama principal
git config --global init.defaultBranch main
Iniciar git, en la ruta actual:
git init
Cambiar el nombre de Master a MAIN
git branch -m main
Ver si hay archivos nuevos en el fs:
git status
Agregar un archivos especifico al git:
git add commands.md
Agregar todos los archivos de la carpeta al git:
git add .
Eliminar el archivo del git, pero los mantiene en el disco duro
git rm --cached commands.md
Eliminar el archivo del git, y tambien elimina del disco duro
git rm --force commands.md
Enviar el archivo al repositorio del git con comantario:
git commit -m "Este es el primer commit"
Enviar el archivo al repositorio del git sin comentario:
Abre un VIM, pero para guardar es "SHIFT+z+z"
git commit
Ver los commits del archivo:
git log commands.md
Ver los cambios del archivo:
git show commands.md
Ver la diff de dos commtis diferentes:
git diff 75ba5f889a93c3d967f929bfa2ad60d25ad8318b 25bb18b3ccf92fcfeb6130a56c6be2c2bb1580fa
Regresar a una version anterior, sin conciderar los archivos q estanen stage
git reset f273dcc4d123b53dbec46f3a614c45b4ac39514b --hard
Regresar a una version anterior, conciderando los archivos q estanen stage
git reset f273dcc4d123b53dbec46f3a614c45b4ac39514b --soft
Ver los commits especificaos en los archivos
git log --stat
Para obtemer el archivo de un determinadon commit
git checkout 25bb18b3ccf92fcfeb6130a56c6be2c2bb1580fa commands.md
git checkout master commands.md
Comando para hacer add y commit, pero esto solo funciona con archivos que hayan tenido add previamente.
git commit -am "Ingresar mensaje del commit"
git branch developer
git checkout developer
git branch
Hacer merge en el master, trayendo los cambios del developer
para hacer el marge los repos deben estar commiteados
git merge developer
ssh-keygen -t rsa -b 4096 -C "[email protected] "
Comprobar proceso, agregarlo y listar
eval $(ssh-agent -s)
ssh-add ~/.ssh/id_rsa
ssh-add -l
Agregar las configuraciones ssh
vim ~/.ssh/config
Host *
AddKeysToAgent yes
UseKeychain yes
IdentityFile ~/.ssh/id_rsa
ssh-add -k ~/.ssh/id_rsa
Listar los repos remotos (Github)
git remote
Crear el repo remoto origin:
git remote add origin https://github.com/giovedy182/curso_git.git
Lista los repos remotos con detalle:
git remote -v
origin https://github.com/giovedy182/curso_git.git (fetch)
origin https://github.com/giovedy182/curso_git.git (push)
Hacer push al origin (Github) desde el repo local main:
git push origin main
La primera vez sale este conflicto:
! [rejected] main -> main (fetch first)
hint: Updates were rejected because the remote contains work that you do not
hint: have locally. This is usually caused by another repository pushing to
hint: the same ref. If you want to integrate the remote changes, use
hint: 'git pull' before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
Para correcgirlo ejecutar un pull:
git pull origin main
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0 (from 0)
Unpacking objects: 100% (3/3), 886 bytes | 80.00 KiB/s, done.
* branch main -> FETCH_HEAD
* [new branch] main -> origin/main
fatal: refusing to merge unrelated histories
Para corregir ejecutar el pull --allow-unrelated-histories
git pull origin main --allow-unrelated-histories
Deberia de mostrar este mensaje de ok:
* branch main -> FETCH_HEAD
Merge made by the 'ort' strategy.
1 file changed, 2 insertions(+)
create mode 100644 README.md
git log --all --graph --decorate --oneline
git config --global alias.logtree "log --all --graph --decorate --oneline"
git config --global alias.superlog "log --graph --abbrev-commit --decorate --date=relative --format=format:'%C(bold blue)%h%C(reset) - %C(bold green)(%ar)%C(reset) %C(white)%s%C(reset) %C(dim white)- %an%C(reset)%C(bold yellow)%d%C(reset)' --all"
git logtree
git superlog