# Abrir el navegador con información sobre un comando:
$ git command --help
git config --list
git config --local --list
git config --global --list
git config --system --list
git config --global user.name "Your name"
git config --global user.email "[email protected]"
git config --global color.ui auto
git config --global core.editor vi
git config --global core.editor "code --wait"
git config --global init.defaultBranch main
<repo>/.git/config
~/.gitconfig
/etc/gitconfig
Existen dos maneras:
Vía SSH:
git clone ssh://[email protected]/repo.git
Vía HTTP:
git clone http://dominio.com/usuario/repo.git
git init
git clone . /folder/to/the/project
git status
git diff
git add .
git add -p <archivo>
git commit -a
git commit
git commit -m 'Aquí el mensaje'
git commit -am 'aquí el mensaje'
git commit --date="`date --date='n day ago'`" -am "Mensaje del commit"
⚠️ ¡No modificar commits ya publicados!
git commit -a --amend
GIT_COMMITTER_DATE="date" git commit --amend
git commit --amend --date="date"
git stash
git checkout branch2
git stash pop
git stash apply
git stash drop
git grep "Hola"
git grep "Hola" v2.5
Mostrar todos los commits, empezando por los más recientes (se mostrará el hash, información sobre el autor, fecha y título del commit)
git log
git log --oneline
git log --author="usuario"
git log -p <archivo>
git log --oneline <origin/master>..<remote/master> --left-right
git blame <archivo>
git reflog show
git reflog delete
git ls-remote <repo>
git branch
git branch -r
git branch -a
git branch -rv
git checkout <rama>
git checkout -b <rama>
git branch <nueva-rama>
git branch --track <nueva-rama> <repositorio>/<rama-remota>
git branch -d <rama>
⚠️ ¡Se perderán los cambios sin fusionar!
git branch -D <branch>
git push [remote] :[branch]
git tag <tag-name>
git tag -a <etiqueta>
git tag -d 12345
git push origin :refs/tags/12345
Otra forma:
git push --delete origin tagName
git remote -v
git remote show <remoto>
git remote add <remoto> <url>
git fetch <remoto>
git remote pull <remote> <url>
git pull origin master
git pull --rebase <remote> <branch>
git push remote <remoto> <rama>
git push <remoto> :<rama> (desde Git v1.5.0)
git push <remoto> --delete <rama> (desde Git v1.7.0)
git push --tags
git merge <rama>
⚠️ ¡No hacer rebase de commits ya publicados!
git rebase <rama>
git rebase --abort
git rebase --continue
git mergetool
Usar tu editor para manualmente resolver conflictos y (después de resueltos) marcar el archivo como resuelto
git add <archivo-resuelto>
git rm <archivo-resuelto>
git rebase -i <commit-just-before-first>
Ahora reemplazando esto,
pick <commit_id>
pick <commit_id2>
pick <commit_id3>
con esto,
pick <commit_id>
squash <commit_id2>
squash <commit_id3>
git reset --hard HEAD
git reset HEAD
git checkout HEAD <archivo>
git checkout .
git revert <commit>
git reset --hard <commit>
git reset HEAD@{index}
git reset --hard <remote/branch> es decir, upstream/master, origin/my-feature
Reestablecer tu puntero HEAD a un commit anterior y preservar todos los cambios en el área de pruebas (stage area)
git reset <commit>
Reestablecer tu puntero HEAD a un commit anterior y preservar los cambios locales sin confirmar (uncommitted changes)
git reset --keep <commit>
Remover los archivos que fueron accidentalmente agregados al commit antes de ser añadidos al fichero '.gitignore'
git rm -r --cached .
git add .
git commit -m "remove xyz file"
git init
git add --all
git commit -m "First Commit"
git tag -a v1.0.0 -m "Message"
git remote add origin {url}
git push -u origin master
git clone {url}
git push [remote] --all
git push [remote] --tags
Mantener el 'fork' de un proyecto actualizado con los cambios del autor original:
# Clonar nuestro fork del otro proyecto
$ git clone [email protected]:YOUR-USERNAME/YOUR-FORKED-REPO.git
# Añadir la URL del repositorio original
$ cd into/cloned/fork-repo
$ remote add upstream git://github.com/ORIGINAL-DEV-USERNAME/REPO-YOU-FORKED-FROM.git
$ git fetch upstream
# Actualizar su bifurcación desde el repositorio original para mantenerse al día con sus cambios
$ git pull upstream master
Cambiar la dirección de correo de todos los commits de un repositorio:
git filter-branch -f --env-filter '
if test "$GIT_AUTHOR_EMAIL" != "[email protected]"
then
[email protected]
fi
if test "$GIT_COMMITTER_EMAIL" != "[email protected]"
then
[email protected]
fi
' -- --all
git lfs install` # You only need to run this once per user account
git lfs track "*.psd"`
git add .gitattributes` # Now make sure _.gitattributes_ is tracked
git add file.psd`
git commit -m "Add design file"`
git push origin master`
# Autenticarse con la cuenta de Github
$ gh auth login
# Mostrar información de la autenticación
$ gh auth status
gh repo list
- https://git-scm.com/docs
- https://git-scm.com/book/es/v2
- https://services.github.com/on-demand/downloads/github-git-cheat-sheet.pdf
- http://ndpsoftware.com/git-cheatsheet.html
- http://ohshitgit.com
- https://github.com/arslanbilal/git-cheat-sheet/blob/master/other-sheets/git-cheat-sheet-es.md
- https://github.com/git-tips/tips
- https://codewords.recurse.com/issues/two/git-from-the-inside-out
- https://cli.github.com/
- https://udacity.github.io/git-styleguide/
Esta obra está bajo una licencia de Creative Commons Reconocimiento-Compartir Igual 4.0 Internacional.