Notas personales y fundamentos sobre Git, basadas en la documentación oficial
# Abrir el navegador con información sobre un comando
$ git {command} --helpgit config --listgit config --local --listgit config --global --listgit config --system --listgit config --global user.name "Your name"git config --global user.email "your_mail@mail.com"git config --global color.ui autogit config --global core.editor vi
git config --global core.editor "code --wait"git config --global init.defaultBranch main<repo>/.git/config~/.gitconfig/etc/gitconfigExisten dos maneras:
Vía SSH:
git clone ssh://usuario@dominio.com/repo.gitVía HTTP:
git clone http://dominio.com/usuario/repo.gitgit initgit clone . /folder/to/the/projectgit statusgit diffgit add .git add -p <archivo>git commit -agit commitgit 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 --amendGIT_COMMITTER_DATE="date" git commit --amendgit commit --amend --date="date"git stash
git checkout branch2
git stash popgit stash applygit stash dropgit loggit log --onelinegit log --author="usuario"git log -p <archivo>git log --oneline <origin/master>..<remote/master> --left-rightgit reflog showgit reflog deletegit ls-remote <repo>git branchgit branch -rgit branch -agit branch -rvgit 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 12345git push origin :refs/tags/12345Otra forma:
git push --delete origin tagNamegit remote -vgit remote show <remoto>git remote add <remoto> <url>git fetch <remoto>git remote pull <remote> <url>git pull origin mastergit 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 --tagsgit merge <rama>⚠️ ¡No hacer rebase de commits ya publicados! ⚠️
git rebase <rama>git rebase --abortgit rebase --continuegit mergetoolgit 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 HEADgit add)git reset HEADgit 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-featuregit reset <commit>git reset --keep <commit>git rm -r --cached .
git add .
git commit -m "remove xyz file"git blame <archivo>git grep "cadena_a_buscar"git grep "cadena_a_buscar" v2.5git 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] --tagsMantener el ‘fork’ de un proyecto actualizado con los cambios del autor original:
# Clonar nuestro fork del otro proyecto
$ git clone git@github.com: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 masterCambiar la dirección de correo de todos los commits de un repositorio:
git filter-branch -f --env-filter '
if test "$GIT_AUTHOR_EMAIL" != "your_email@mail.com"
then
GIT_AUTHOR_EMAIL=your_email@mail.com
fi
if test "$GIT_COMMITTER_EMAIL" != "your_email@mail.com"
then
GIT_COMMITTER_EMAIL=your_email@mail.com
fi
' -- --allgit 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 statusgh repo list Esta obra está bajo una licencia de
Creative Commons Reconocimiento-Compartir Igual 4.0
Internacional.