Skip to content

Instantly share code, notes, and snippets.

@fitomad
Last active May 23, 2023 11:05
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save fitomad/6749d12f33328fc8418d091be8f556d2 to your computer and use it in GitHub Desktop.

Crear un branch local y subirlo a remoto

git branch NEW-BRANCH-NAME
git push -u origin <branch>

Renombrar un branch local

git branch -m nuevo_nombre

Borrar un branch local

git branch -D myBranch

Borrar un branch remoto

git push origin --delete myRemoteBranch 

Cuando se cambia el nombre de una rama en remoto

git branch -m master main
git fetch origin
git branch -u origin/main main
git remote set-head origin -a

Listar todas las branch remotas

git branch -r

Recuperar un branch remoto

git switch remote_branch

Crear tag y subirlo a remoto

git tag <tagname> -a
git push origin --tags

Dejar sólo el último commit en un respositorio GIT

  1. Borramos el historial
rm -rf .git
  1. Recreamos el repositorio a partir del contenido actual
git init
git add .
git commit -m "Initial commit"
  1. Push al servidor Git asegurándonos de sobreescribir el historial
git remote add origin git@github.com:fitomad/CoreEMT.git
git push -u --force origin master

Añadir un remote al repositorio

El comando es

git remote add [nombre] [URL del repositorio]

por ejemplo...

git remote add my_awesome_new_remote_repo git@git.assembla.com:portfolio/space.space_name.git

Merge

git checkout <branch_en_la_que_quiero_poner_los_cambios_de_la_otra>
git merge <branch_con_los_cambios>
git push 
git push origin <branch_actual>

Patch

git diff --binary > file.patch
git apply file.patch

Stash. Guardar trabajo y recuperarlo después

El comando stash almacena temporalmente (o guarda en un stash) los cambios que hayas efectuado en el código en el que estás trabajando para que puedas trabajar en otra cosa y, más tarde, regresar y volver al punto donde lo habías dejado.

git stash

Cuando quiera recuperar de nuevo el trabajo no salvado...

git stash pop

Forzar a que la rama remota acepte los cambios locales

git push -f origin develop

Forzar a que la rama local obtenga la última versión de la remota

  1. Nos situamos en la rama local elegida
  2. Forzamos el reseteo
git switch remote_branch
git reset --hard origin/remote_branch

Establer tu usuario de GitHub para un único repositorio

  1. Abrir la aplicación Terminal
  2. Situarse en el directorio del repositoria donde queremos configurar otro nombre de usuario

Ejecutar el siguiente comando

$ git config user.name "fitomad"

Para comprobar que lo hemos escrito correctamente:

$ git config user.name
> fitomad

Problemas con las referencias en repos muy antiguos con muchas ramas

Git Error: (unable to update local ref)
git gc --prune=now
git remote prune origin

git remote -v
git remote rm origin
git remote add origin **Repository URL**
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment