Skip to content

Instantly share code, notes, and snippets.

@icalderond
Last active November 26, 2021 23:15
Show Gist options
  • Save icalderond/e13d1ac2a38460880e83020c23c3da2e to your computer and use it in GitHub Desktop.
Save icalderond/e13d1ac2a38460880e83020c23c3da2e to your computer and use it in GitHub Desktop.
Comandos GIT
# Change editor replacing VIM editor with VS Code
# On macOS
git config --global core.editor "code-insiders --new --wait"
# On Windows
git config --global core.editor "'C:\Program Files\Sublime Text 3\sublime_text.exe' -new -w"
# Command dictionary
# --new , -n : Open editor on new window
# --wait, -w : When editor is closed the terminar is enable for contoune wrriting more commands
# Crear nuevo brach y hacer un checkout al nuevo branch
git checkout -b hotfix
# Crear una nueva rama
git branch [nombre_rama]
# Renombrar rama
git branch -m [oldName] [newName]
# Remover rama existente
git branch -d [branchName]
# Remover rama con cambios ya en la rama
git branch -D [branchName]
# Remover rama existente en remoto
git push origin --delete feature/login
# Editar un comment de un commit ya pushed
git commit --amend
(teclear la letra i para editar el comentario)
(teclear la tecla esc para salir del modo inserción )
(teclear :wq para guardar cambios y salir)
git push --force <repository> <branch>
# Basic commit
git commit -m "My message"
# Commit customized
# Add alias for add files and commit on same line
git config --global alias.add-commit '!git add -A && git commit'
# How to use this command
git add-commit -m 'My commit message'
#Add only files with specific ending text
git add \*.jpg \*.png
git diff [sha1]
git diff [sha1] [sha1]
git diff [tag1] [tag2]
# rm all files
git rm -r --cached .
# add all files as per new .gitignore
git add .
# now, commit for new .gitignore to apply
git commit -m ".gitignore is now working"
# create command for show information with command 'superlog'
# more info https://git-scm.com/docs/git-log
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"
# Coloca los commits de manera resumida y en una sola línea.
git log --oneline
# Nos mostraria los diferentes commits en las ramas o bifurcaciones con un asterisco.
git log --oneline -–graph
# Nos permite ver los últimos commits
#git log -10
There is a simple solution based on Git stash. Stash everything that you've changed, pull all the new stuff, apply your stash.
git stash
git pull
git stash pop
# ===============BRANCH===============
# Push your branch to the remote repository:
git push -u origin feature_branch_name
# Remove branch from server already deleted on local
# git push <remote_name> :<branch_name>
git push origin --delete israelca-c
# ===============TAGS===============
# delete remote tag '12345' (eg, GitHub version too)
git push origin :refs/tags/12345
# alternative approach
git push --delete origin tagName
git tag -d tagName
# ===============COMMENTS/COMMIT===============
# Editar un comment de un commit ya pushed
git commit --amend
(teclear la letra i para editar el comentario)
(teclear la tecla esc para salir del modo inserción )
(teclear :wq para guardar cambios y salir)
git push --force <repository> <branch>
# Delete the last commit
git reset HEAD^ --hard
# Tres tipos de reset
# Soft, mixed, hard
# Desde que commit queremos quitar los cambios. Solo quita los commits
git reset --soft [sha1]
# Descarta cambios y quita los commits y los quita del stage
git reset --mixed [sha1]
# Borra todo, hasta los archivos. Solo los que esten en el stage
# Una vez reseteado hasta una historia muy antes se puede regresar al ultimo usando el ultimo sha1
git reset --hard [ash1]
# Remove from stage a file
git reset HEAD [file]
# Remove last commit. Result: Changes keep on stage
git reset --soft HEAD~
# Remove file from stage
git reset HEAD <file>
#reset last commit of remote
git reset HEAD^ # remove commit locally
git push origin +HEAD # force-push the new HEAD commit
# Generate generic SSH not email
ssh-keygen -t rsa
# Generate SSH with email
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
# Copy SSH in mac
pbcopy < ~/.ssh/id_rsa.pub
# GET TAGS
-------------------------------
#Show tags
git tag -l
---------------------------------------------------------
#Agregar un tag
git tag -a v1.4 -m "my version 1.4"
#Subir el tag
git push --tags
---------------------------------------------------------
Mostrar el tag actual en donde se encuentra el proyecto
git describe --tags
---------------------------------------------------------
Hacer un checkout a un tag especifico
First make sure that the tag exists locally by doing
# --all will fetch all the remotes.
# --tags will fetch all tags as well
git fetch --all --tags --prune
Then check out the tag by running
git checkout tags/<tag_name> -b <branch_name>
Instead of origin use the tags/ prefix.
---------------------------------------------------------
# delete local tag '12345'
git tag -d 12345
# delete remote tag '12345' (eg, GitHub version too)
git push origin :refs/tags/12345
# alternative approach
git push --delete origin tagName
git tag -d tagName
#tag older commit
git tag -a v1.2 9fceb02 -m "Message here"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment