EXTRAS:
Fundamental commands for git bash
How to make a save all changes and commit on a single line. (Linux / Git bash)
- Modificar ~/.gitconfig
En este archivo se pueden excluir los archivos, carpetas y tipos de archivos que no se quieren incluir en el repositorio.
- Crear una carpeta con el nombre que queremos que tenga el repostorio.
mkdir my_repo
- Inicializar un nuevo repositorio git dentro de la carpeta.
cd nom_dossier
git init
- Creamos un archivo python
nano hello.py
#! /usr/bin/env python3
print("Hello World !")
- Hacer el fichero ejecutable.
chmod +x hello.py
- Testear la ejecución del archivo.
./hello.py
, la salida obtenida será : Hello World !
- Ver las modificaciones realizadas.
git status
- Agregar el archivo 'hello.py'al repositorio.
git add hello.py
- Volvemos a ver las modificaciones al repositorio.
git status
- Antes de realizar el commit es necesario identificarse globalmente en git local para registrar en el repositorio quien realizó los cambios.
*** Please tell me who you are. Run
git config --global user.email "you@example.com" git config --global user.name "Your Name"
to set your account's default identity. Omit --global to set the identity only in this repository.
- Creamos el commit.
git commit -m "My first commit !"
- Si observamos las modifiacioens ahora veremos que todo fue salvado y no hay nada pendiente.
git status
- Podemos ver el historial de la siguiente forma.
git log
(alt: git log --oneline
)
- Generaremos un error en el archivo python.
#! /usr/bin/env python3
print("Hello World
- Ejecutamos el archivo.
./hello.py
Se obtiene la salida:
File "./hello.py", line 3
print("Hello World !
^
SyntaxError: EOL while scanning string literal
- Ver las modificaciones realizadas.
git status
- Eliminar las modificaciones.
git checkout -- hello.py
- Ver las modificaciones realizadas
git status
- Ejecutar el archivo de nuevo
./hello.py
Salida obtenida : Hello World !
- Revisar el archivo.
cat hello.py
- Modificar el archivo python
Remplazar print("Hello World")
por
print("Hello, my name is PUT\_YOUR\_NAME\_HERE")
- Ver las modifiaciones
git status
- Agregar el archivo.
git add hello.py
- Crear el nuevo commit
git commit -m "My presentation"
- Ver el historial
git log
- Ver el hash identificatorio del primer commit
git log --oneline
- Ver la diferencia
git diff HASH\_PRIMER\_COMMIT
- Voir ce que contient l'avant dernier commit
git show HEAD^1
- Reset (soft)
git reset HEAD^1
- Ver las modificaciones realizadas
git status
- Modificar el archivo en python de la siguiente forma
Original:
name = "PUT\_YOUR\_NAME\_HERE"
print("Hello, my name is", name,"and you ?")
Modificado:
name = "PUT\_YOUR\_NAME\_HERE"
print("Hello, my name is", name,". I need to go now, bye !")
- Agregar las modificaciones
git add hello.py
- Commitear
git commit -m "Je dois partir"
- Ver las modificaciones
gitk
-
Créer un compte GitHub
-
Créer un répertoire GitHub
-
Récupérez l'URL
-
Rajoutez le remote
git remote add origin PUT\_URL\_HERE
- Voir si tout s'est bien déroulé
git remote -v
- Envoyer son code sur le remote
git push origin master
- Aller dans un autre dossier qui n'est pas un répertoire git
Par exemple : cd ..
- Cloner le repository
git clone URL local_path_new_folder
- Executer le fichier
./hello.py
- Player one : modifier le code
#! /usr/bin/env python3
name = "..."
print("Hello, my name is", name,". I need to go now, bye !")
print("Oups no, this is not my name")
- Voir les modifications apportées
git status
- Ajouter le fichier
git add hello.py
- Commiter le fichier
git commit -m "Not my name"
- Envoyer les modifications à tout le monde
git push origin master
- Player two : récupérer le code
git pull origin master
- Executer le fichier
./hello.py
- Player two : Modification du fichier
Rajouter la ligne : print("I am the player two")
- Player one : Modification du fichier
Rajouter la ligne : print("I am the player one")
- Player one : Envoie ses modifications
git status
git add hello.py
git commit -m "Je suis le player one"
git push origin master
- Player two : Envoie ses modifications
git status
git add hello.py
git commit -m "Je suis le player two"
git push origin master
- Récupération des modifications
git pull
- Voir ce qu'il se passe
git status
- Voir le détail des erreurs
git diff
- Correction des erreurs
Supprimer tout ce qui est entre <<<< HEAD et >>>>
, sauf print("I am the player two")
- Voir les modifications apportées
git status
- Ajouter les modifications
git add hello.py
git commit
: Sauvegarder le fichier qui va s'ouvrir (Vim : tapez :wq
)
- Voir la modification de l'historique
gitk
- Envoyer les modifications
git push
- Récupérer les dernières modifications
git pull
- Voir ce qu'il s'est passé
gitk
- Executer le fichier
hello.py
Teacher : explain how systems like GitHub's Pull Requests could prevent this.
Teacher : show him
- Toujours vérifier les dernières modifications
git pull origin master
- Voir les différentes branches disponibles
git branch
- Créer une nouvelle branche et s'y déplacer
git checkout -b branche_of_two
- Voir les différentes branches
git branch
- Créer le fichier
main.py
#! /usr/bin/env python3
import one
if __name__ == "__main__":
one.hello_world()
- Ajouter le fichier main.py
git add main.py
- Rebasculer sur master
git checkout master
- Voir que le fichier nous a suivit
git status
- Rebasculer sur la branche
git checkout branche_of_two
- Committer le fichier
git commit -m "Add the main file"
- Voir les modifications
git log --oneline
- Envoyer les modifications
git push
- Retourner sur master
git checkout master
- Récupérer la dernière version
git pull origin master
- Voir les fichiers présents sur master
ls
Changements :
- "main.py" => "one.py"
#! /usr/bin/env python3
def hello_world():
print("Hello world ! We are player two and one !")
-
branche_of_two => branche_of_one
-
Message du commit => "Add the hello_world feature"
-
Teacher : show how to create pull requests (with the rebase button obviously)
-
Récupérer les dernières modifications
git checkout master
git pull origin master
- Voir l'historique
gitk
- Executer le fichier
./hello.py