INTRODUCCIÓN A GIT




Maximiliano Osorio

Control de versiones


¿Que es un sistema de control de versiones y porque debiera importarte?
Un sistema de control de versiones guarda los cambios de un archivo o un set de archivos durante un tiempo para que puedas revisar versiones anteriores después.
http://git-scm.com/book/en/Getting-Started-About-Version-Control, 2013

Control de versiones


En general, te permite: 

  • Revertir los archivos a un estado anterior
  • Revertir el proyecto completo anterior
  • Revisar los cambios durante todo el tiempo
  • Ver quien  y cuando hizo algo para buscar el problema

 Using a VCS also means that if you screw things up or lose files, you can generally recover easily. In addition, you get all this for very little overhead.

¿Que es git?



 git: A silly, incompetent, stupid, annoying or childish person.
http://en.wiktionary.org/wiki/git

"I'm an egotistical bastard, and I name all my projects after myself. First 'Linux', now 'git'."
Linus Torvalds

Uso de git


  • Kernel de Linux
  • Google
  • Facebook
  • Twitter
  • Linkedin
  • Netflix
  • Perl
  • Postgresql

Quien usa git?



  • Rails
  • Android
  • Qt
  • Gnome
  • Microsoft
  • etc

CARACTERÍSTICAS de git


  • Veloz
  • Diseño simple
  • Totalmente distribuido
  • Soporte para ramas en paralelos
  • Integridad de archivos (SHA1)

Git thinks of its data more like
 a set of snapshots of a mini filesystem.

Instalación de git


Linux

yum install git (RHEL, Fedora, CentOS)

apt-get installl git-core (Debian, Ubuntu, LinuxMint)


Otros


http://git-scm.com/download/mac
http://git-scm.com/download/windows

Advertencia


git al inicio no es fácil de comprender
menos de usar.
Pero totalmente sencillo. Y cuando lo aprendes a usar.
 ¡Es genial! 

Si te está dando un dolor de cabeza al inicio.
Vas bien.

EStructura


Tres estados:

  • Committed: confirmado
  • Modified: Modificado
  • Staged: Preparado

eSTRUCTUrA



Libro Progit

Configuración

Identidad

$ git config --global user.name "John Doe"
$ git config --global user.email johndoe@example.com

Editor

$ git config --global color.ui true

Colores

$ git config --global color.ui true

Creando un repositorio




$ git init

Clonando un repositorio


$ git clone <url support https, ssh>


Por ejemplo

$ git clone git@github.com:openshift/origin-server.git

creando un commit


Imaginemos que hicimos un nuevo archivo llamado: ejercicio1b.py 

¿Que hacemos?


revisar el estado actual


$ git status

# On branch master
#
# Initial commit
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#	ejercicio1b.py
nothing added to commit but untracked files present (use "git add" to track)

Estado: un archivo en la carpeta, git ni lo mira

aÑADIR EL ARCHIVO


$ git add ejercicio1b.py

Luego podemos verificar con $git status
$ git status
# On branch master
#
# Initial commit
#
# Changes to be committed:
#   (use "git rm --cached <file>..." to unstage)
#
#	new file:   ejercicio1b.py

Estado: un archivo en staged aun no ha sido confirmado

creando el commit




$ git commit -am "Mensaje significado de lo que hizo" 



Removiendo archivos


Desde el staging area
$ git rm --cached file.py

De git y el sistema de archivo
$ git rm file.py

GITIGNORE

REMOTES


  • Otros commits del repositorio pueden ser locales o remotos
  • Por defecto, lo default son

git remote -v 
origin	git@forge.inf.utfsm.cl:mosorio-personal/test2.git (fetch)
origin	git@forge.inf.utfsm.cl:mosorio-personal/test2.git (push




Hasta ahora, todo ha sido local.

Ahora añadamos un servidor.

aÑADIR EL SERVIDOR REMOTO


Ejemplo de lo que verán
git remote add origin git@forge.inf.utfsm.cl:mosorio-personal/test2.git


eNVIAR LOS CAMBIOS AL SERVIDOR


Enviar los cambios (no significa que vamos a usar el servidor después)

$ git push origin master

Enviar los cambios y dejar el servidor como defecto. 
Lo que deben hacer ustedes

$ git push -u origin master


TRAER CAMBIOS


Si esta por defecto el servidor, necesitamos

git pull

Repasemos


Traemos los cambios 
$ git pull

Añadimos archivos si existen

$ git add file

Confirmamos los cambios (commit)

$ git commit -a -m "Solución al bug 73, la respuesta del universo"

Enviamos los cambios.

$ git push


git

By sirspock

git

  • 302