GIT

Sistemas de Control de Versiones - VCS

Contenido

  • Sistemas de Control de Versiones
  • ¿Qué es GIT?
  • Instalación y configuración
  • Conceptos fundamentales
  • Más herramientas

Sistema de Control de Versiones - Locales

  • PRO: Simple
  • CONTRA: Fácil equivocarse, falta la dimensión colaborativa
Sistema de Control de Versiones Locales

Sistema de Control de Versiones - Centralizados

  • PRO: Introduce colaboración
  • CONTRA: Depende de un único servidor con posible pérdida de datos
Sistema de Control de Versiones Centralizado

Sistema de Control de Versiones - Distribuidos

  • Réplica total del repositorio
Sistema de Control de Versiones Distribuido

¿Qué es GIT?

  • Sistema de Control de Versiones Distribuida (DVCS)
  • Open Source
  • Garantiza integridad de los datos
  • Alto rendimiento

Open Source

código fuente disponible:

https://github.com/git/git

Integridad

Conjunto de instantáneas de un mini sistema de archivos

Integridad

  • se calcula un hash de cada instantánea
  • SHA-1 checksum, 40 caracteres
  • se verifica antes de escribir cualquier dato

Ejemplo de sha1

Calculamos el sha-1 de la palabra "versionamiento"

La misma palabra (o archivo) genera siempre el mismo hash


$ echo -n versionamiento | sha1sum

103e878be00120776aa8682e848253d7c3678d12  -
          

Alto Rendimiento

Instalación

Linux:

apt-get install git # Debian / Ubuntu
yum install git-all # Fedora
Windows:

git-scm.com/download/win

Mac:

git-scm.com/download/mac

Configuración

Establecer nombre y correo electrónico


git config --global user.name "Elmer Mendoza"
git config --global user.email "defreddyelmer@gmail.com"

Ver la configuración establecida (~/.gitconfig)


git config --list

user.name=Elmer Mendoza
user.email=defreddyelmer@gmail.com

Conceptos fundamentales

Los tres estados y áreas

Iniciando con el proyecto

git init, git clone

Desde un directorio local


git init

Desde un repositorio existente


git clone https://IP_O_DOMINIO_SERVIDOR_REMOTO/nombre-proyecto.git

Verificando el estado del proyecto

git status

git status

On branch master
Changes to be committed:
	new file:   INSTALL.md

Changes not staged for commit:
	modified:   index.html

Flujo de cambios

Añadiendo cambios

git add

git add [nombre-archivo]

git add index.html INSTALL.md

git add .

Confirmando cambios

git commit

git commit -m "Mensaje que describe el cambio"

Adicionar y confirmar todos los cambios


git commit -a

Historial de los commits

git log, git show [hash-de-commit]

commit 8fa49b94256bce45e6017eb807b67f5fee2fa77b
Author: Mary Rosales 
Date:   Mon Jan 8 11:59:07 2018 -0400

    Agregando conceptos de integridad

commit eda9eb790a1d366b46b28b120fb3e8ac98421c88
Author: Elmer Mendoza 
Date:   Mon Jan 8 11:40:11 2018 -0400

    Adición de conceptos fundamentales sobre VCS

Listar repositorios remotos


git remote --verbose

gitlab  https://gitlab.com/elmerfreddy/git.git (fetch)
gitlab  https://gitlab.com/elmerfreddy/git.git (push)
origin  https://github.com/elmerfreddy/git.git (fetch)
origin  https://github.com/elmerfreddy/git.git (push)

Repositorios remotos

Añadir repositorio remoto


git remote add [nombre-repositorio] [url-repositorio]

Eliminar repositorio remoto


git remote rm [nombre-repositorio]

Recibiendo del repositorio remoto

git pull

git pull [nombre-repositorio] [nombre-rama]

git pull origin master

From https://github.com/elmerfreddy/git
 * branch            master     -> FETCH_HEAD
Updating fa3bfeb..d59d2b1
Fast-forward
 img/basic-remote-workflow.png | Bin 0 -> 76802 bytes
 img/flujo.png                 | Bin 0 -> 7745 bytes
 img/rendimiento.png           | Bin 0 -> 19442 bytes
 img/staging.jpg               | Bin 0 -> 66869 bytes
 index.html                    |  96 ++++++++++++++++++++++++++++++++
 5 files changed, 96 insertions(+)
 create mode 100644 img/basic-remote-workflow.png
 create mode 100644 img/flujo.png
 create mode 100644 img/rendimiento.png
 create mode 100644 img/staging.jpg

Enviando al repositorio remoto

git push

git push [nombre-repositorio] [nombre-rama]

git push origin master

Counting objects: 5, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (5/5), done.
Writing objects: 100% (5/5), 8.04 KiB | 0 bytes/s, done.
Total 5 (delta 3), reused 0 (delta 0)
remote: Resolving deltas: 100% (3/3), completed with 3 local objects.
To https://github.com/elmerfreddy/git.git
   ee9f91f..d59d2b1  master -> master

RAMAS

HEAD

Apuntador a la rama local en la que nos encontramos en ese momento.

Crear una nueva rama

git branch

$ git branch NOMBRE_DE_LA_RAMA #crea la rama
$ git checkout -b NOMBRE_DE_LA_RAMA  # crea la rama y entra a la misma
          

Cambiar de rama

git checkout

$ git checkout NOMBRE_DE_LA_RAMA
          

Unir dos ramas

git merge

$ git merge NOMBRE_DE_LA_SEGUNDA_RAMA
          

Más herramientas

  • stash
  • blame
  • cherry-pick
  • reset
  • reflog

Gracias

Lecturas recomendadas