Skip to content

Instantly share code, notes, and snippets.

@RodolVelasco
Created October 19, 2018 20:29
Show Gist options
  • Save RodolVelasco/e6af0d59273e899b0d02e8eb37ff2383 to your computer and use it in GitHub Desktop.
Save RodolVelasco/e6af0d59273e899b0d02e8eb37ff2383 to your computer and use it in GitHub Desktop.
git commands
@RodolVelasco
Copy link
Author

Add a git remote repository from Github

git remote add origin https://github.com/RodolVelasco/fortuna.git

@RodolVelasco
Copy link
Author

RodolVelasco commented Nov 1, 2018

For the First commit ever, adding remote repo already created in github

Iniciar el repo
git init
Añadir files
git add .
Primer commit with message
git commit -m "Initial commit"
Add git remote repo
git remote add origin https://github.com/RodolVelasco/fortuna.git
Push to the repo
git push -u origin master

Código desde distintas máquinas

Cuando yo mismo ande metiendo código en distintas máquinas, puedo usar este comando para halar el código del repositorio
git pull origin master

@RodolVelasco
Copy link
Author

RodolVelasco commented Feb 26, 2019

GIT comandos básicos

Comparar
diff -u old.html new.html

Log de commits
git log

Comparar versiones del mismo file por id commit
git diff commit_id1 commit_id2

image

Regresar a una version previa (checkout)
git checkout id_commit

Para crear un checkout con una nueva branch (utilizar nuevamente checkout para lograr este comportamiento)
git checkout -b branch_name

image

Diferencia entre working directory and staging
git diff

Diferencia entre staging y repository
git diff --staged

Discard any changes in either the working directory or the staging area.
Si se borra, los cambios no pueden ser recuperados
git reset --hard

image

BRANCHES

Muestra listado de branches
git branch
Crear un branch
git branch any_argument
Para ubicarse en un branch
git checkout branch_name
Ver log manera resumida
git log --graph --oneline master branch_name

Remeber that HEAD means current commit.
Un checkout sobre un commit se vería como la siguiente imagen. Se vería sin ninguna branch
image
Este tipo de commits no se muestran con git log ya que no pertenece a ninguna branch
Para incorporarlo vamos a necesitar hacer un git checkout -b new_branch_name esto equivale a hacer dos comandos: git checkout y luego git branch

git show commit_id

Para borrar un branch
git branch -d branch_name
Lo querré borrar luego de haber hecho un merge. Los commits del branch no se pierden ni tampoco los del padre.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment