Skip to content

Instantly share code, notes, and snippets.

@pyjavo
Last active May 10, 2024 18:54
Show Gist options
  • Save pyjavo/1d0b8eb5077f4d32e5b6 to your computer and use it in GitHub Desktop.
Save pyjavo/1d0b8eb5077f4d32e5b6 to your computer and use it in GitHub Desktop.
GIT: Comandos comunes

Creando repositorio

  1. Se crea el repositorio git init

  2. Se suben los archivos a la zona de preparacion git add Xarchivos

  3. Se comenta el porque de esos archivos git commit -m ‘bla bla bla’

  4. En caso de no existir, se añade el repositiorio remoto git remote add origin https://fulanito@bitbucket.org/bla/bla.git git remote add origin https://github.com/USERNAME/PROJECT-NAME

    SSH git remote add origin git@github.com:USERNAME/PROJECT-NAME.git

  5. Se suben los cambios al repositorio Primera vez

     git push origin master
    

    Demas veces

     git push -u origin --all
    

Colaborar con codigo existente

Hacer fork de un codigo en bitbucket/Github. Luego clonarlo, cambiarlo, y hacer un pull request al dueño del branch original

Clonar repo en carpeta nombreNuevo

git clone https://fulanito@bitbucket.org/administrador/nombre-del-repo.git nuevoNombreRepo

Clonar rama especifica de un repo

git clone https://github.com/fulanito/nombre-repo.git -b NOMBRE-RAMA nuevoNombreRepo

Clonar todos los archivo del repo en carpeta actual

git clone https://fulanito@bitbucket.org/fulanito/nombre-del-repo.git .

Añadir archivo

git add ‘.py’

Añadir todos los archivos

git add -A

Remover archivos

git rm ‘.txt’

remover carpetas

git rm -r ‘doodle’

git commit -m “Listo ya añadi tal cosa”

branching out

git branch clean_up

Ver todas las ramas (incluso las escondidas)

git branch -a

switching to clean_up

git checkout clean_up

Cambiar a la rama master

git checkout master

Cambiarse a una rama que ya estaba creada en el repo origen

git checkout -b BRANCH-NAME origin/BRANCH-NAME

git merge clean_up

Delete brand clean_up

git branch -d clean_up

PUSH to remote repository

git push https://fulanito@bitbucket.org/fulanito/proyecto-version01.git

Saber que archivos están siendo ignorados

git ls-files --others -i --exclude-standard

Remueve todos los arhivos que aparecen como deleted en git

git rm $(git ls-files --deleted)  

Si coloca problemas por cambios y pide stash

git stash

Muestra todos los stash guardados

git stash list

Aplica los cambios que fueron guardados en stash en el directorio actual

git stash pop

Reset para devolverse al ultimo commit del origen

git reset --hard origin/<branch-name>

Revert de un commit que ya fue pusheado

git revert 12e33ce45

Esto devolverá los cambios realizados en el commit 12e33ce45. Luego de ello se pueden resolver conflictos y volver a subir cambios al remoto. Se agregará como un nuevo commit a la historia Fuente:

Delete remote tracking branches

git remote prune origin

Probar código de un Pull Request

git fetch origin pull/1234/head:NOMBRE-PR-1234
git checkout NOMBRE-PR-1234

Merge with no fast forward (one branch to another)

git checkout master
git merge --no-ff -m 'Merged in featuredbranch (pull request #11)' remotes/origin/featurebranch
https://stackoverflow.com/questions/9069061/what-is-the-difference-between-git-merge-and-git-merge-no-ff

Eliminar archivos que deben ser ignorados que ya han sido commiteados

git rm -r --cached .   ( git rm --cached <ARCHIVO> )
git add .
git commit -m ".gitignore ahora esta funcionando"

Limpiando un repo despues de un merge

git clean -fd

Agregando un cambio al último commit

git add ARCHIVO_OLVIDADO
git commit --amend --no-edit
* editar mensaje
git commit --amend

Cambiar de HTTPS a SSH

git remote set-url origin git@github.com:USERNAME/REPOSITORY.git

Cambiar de master a main

git branch -m master main

Actualizando una rama con master

git checkout master
git pull
git checkout development
git merge master

=================================================================================

Bitbucket

Cambiarse a una rama credaa remotamente

git checkout -b hotfix-docker origin/hotfix-docker

=================================================================================

GitLab

If you are using different ssh file instead of the default id_rsa. You need to add that ssh file using ssh-add. run:

ssh-add <PATH-TO-SSH-FILE>

example: ssh-add ~/.ssh/gitlab_rsa

Probar conexión con gitlab:

ssh -T git@gitlab.com

Debe coincidir el ssh host key fingerprint

Si quieres que no te pida el passphrase

vim ~/.ssh/config
  • Luego escribe
Host gitlab.com
  AddKeysToAgent yes
  UseKeychain yes
  PreferredAuthentications publickey
  IdentityFile ~/.ssh/file_gitlab_rsa
  • Ya luego si se hace ssh-add ~/.ssh/gitlab_rsa

Markdown

Video de youtube con enlace

Este video explica para que son los workflw dispatch

Comprehensive Markdown Crash Course

Fuente:

Configuración

git config --global core.editor "vim --nofork"

Etiquetas

git tag -a v1.0 -m "Mensaje para el commit de la etiqueta"
git push origin v1.0

Buenos mensajes para commits

  • Guía: https://www.freecodecamp.org/news/how-to-write-better-git-commit-messages/

    • feat – a new feature is introduced with the changes
    • fix – a bug fix has occurred
    • chore – changes that do not relate to a fix or feature and don't modify src or test files (for example updating dependencies)
    • refactor – refactored code that neither fixes a bug nor adds a feature
    • docs – updates to documentation such as a the README or other markdown files
    • style – changes that do not affect the meaning of the code, likely related to code formatting such as white-space, missing semi-colons, and so on.
    • test – including new or correcting previous tests
    • perf – performance improvements
    • ci – continuous integration related
    • build – changes that affect the build system or external dependencies
    • revert – reverts a previous commit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment