jueves, 22 de noviembre de 2012

git crib

Install git (debian)

sudo apt-get install git-core

Workflow

Generate SSH keys


View: https://help.github.com/articles/generating-ssh-keys

Clone a project (svn checkout equivalent)

git clone https://github.com/username/projectname.git
Creates projectname directory and clones the project.

Add a file to the repository

git add filename

Show project status

git status

Commit to the local repository

git commit -a -m "change description"

Upload to the central repository

git push git@github.com:username/projectname.git
or (see user configuration),
git push

Discard all local changes including newly added files

git reset --hard

Discard options

f you want to revert changes made to your working copy, do this:
git checkout .
If you want to revert changes made to the index (i.e., that you have added), do this:
git reset
If you want to revert a change that you have committed, do this:
git revert ...
Taken from: http://stackoverflow.com/questions/1146973/how-to-revert-all-local-changes-in-a-git-managed-project-to-previous-state

Show differences


Update project, download changes (svn update equivalent)

git pull

Show diff between master and local repository

git diff


Branches


Make a new branch

git branch rama

Show branches

git branch

Go to the branch rama

git checkout rama

Merge with master

git branch master (goto the main branch)
git merge "rama" (merge rama with main)


User configuration


User

To automate the pulls:

View the reponame
git config -l

And then
sudo git config remote.origin.url https://{USERNAME}:{PASSWORD}@github.com/{USERNAME}/{REPONAME}.git

Find all *.pyc and remove from the repository

find . -name "*.pyc" -exec git rm -f {} \;

Ignore some types of files (global)

git config --global core.excludesfile ~/.gitignore_global

Edit ~/.gitignore_global and add patterns like *.pyc

Ignore some types of files (local)

At the local repository edit .gitignore and add patterns.

sábado, 17 de noviembre de 2012

Chuleta de git

Instalar git (debian)

sudo apt-get install git-core

Ciclo de trabajo

Generación de claves SSH


Ver: https://help.github.com/articles/generating-ssh-keys

Clonar un proyecto (equivale a checkout de svn)

git clone https://github.com/nombreusuario/nombreproyecto.git
Crea el directorio nombreproyecto y clona el proyecto en él.

Añadir fichero a repositorio

git add nombrefichero

Ver status del proyecto

git status

Hacer commit al repositorio local

git commit -a -m "descripción de los cambios"

Subir cambios al repositorio central

git push git@github.com:nombreusuario/nombreproyecto.git
o bien,
git push


Descartar cambios locales


i
f you want to revert changes made to your working copy, do this:
git checkout .
If you want to revert changes made to the index (i.e., that you have added), do this:
git reset
If you want to revert a change that you have committed, do this:
git revert ...


Fuente: http://stackoverflow.com/questions/1146973/how-to-revert-all-local-changes-in-a-git-managed-project-to-previous-state



Volver a un commit en concreto

git checkout commit_id

véase: http://stackoverflow.com/questions/4114095/revert-to-previous-git-commit

Ver diferencias


Actualizar el proyecto local, bajar los cambios, hacer "update"

git pull

Ver diferencias entre rama de desarrollo y repositorio local

git diff

Ver diferencias entre repositorio local y HEAD

git diff --cached

Ver diferencias entre rama de desarrollo y HEAD

git diff HEAD

Ramas


Crear rama a partir de la actual

git branch rama

Mostrar ramas y en la que nos encontramos

git branch

Situarnos en una rama

git checkout rama

Merge de una rama "rama" con la principal

git branch master (nos situamos en la rama principal)
git merge "rama" (merge de la rama con la principal)


Configurar usuario


Usuario

Automatizar los pulls:

Ver nombre de repositorio
git config -l

Y con el reponame

sudo git config remote.origin.url https://{USERNAME}:{PASSWORD}@github.com/{USERNAME}/{REPONAME}.git

Encontrar todos los *.pyc y eliminarlos del repositorio
find . -name "*.pyc" -exec git rm -f {} \;

Ignorar algunos tipos de fichero (global)

git config --global core.excludesfile ~/.gitignore_global

Editar ~/.gitignore_global y añadir patrones p.e. *.pyc

Ignorar algunos tipos de fichero (local)

En el repositorio local editar .gitignore y añadir los patrones.