Introducción al manejo de ramas#
Última modificación: Mayo 14, 2022
Se usan para marcar ciertos puntos de la historia del repositorio como importantes, por ejemplo, versiones.
Preparación del proyecto#
[1]:
!rm -rf git-demo
!mkdir git-demo
%cd git-demo
/workspace/git/git-demo
[2]:
!git init
Initialized empty Git repository in /workspace/git/git-demo/.git/
[3]:
!git config user.email "you@example.com"
!git config user.name "john doe"
Rama master
#
[4]:
!touch file_1.txt
!git add file_1.txt
!git commit -m 'create file_1.txt'
[master (root-commit) 061eaf7] create file_1.txt
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 file_1.txt
Creación de una nueva rama#
[5]:
!git branch testing
[6]:
!git status
On branch master
nothing to commit, working tree clean
Creación de un nuevo archivo en la rama master
#
[7]:
!touch file_2.txt
!git add file_2.txt
!git commit -m 'create file_2.txt'
[master 258cd0d] create file_2.txt
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 file_2.txt
[8]:
!ls -1
file_1.txt
file_2.txt
[9]:
!git log --oneline --decorate
258cd0d (HEAD -> master) create file_2.txt
061eaf7 (testing) create file_1.txt
Modificación de un archivo en la rama master
#
[10]:
!echo "line 1 in file_1.txt in master branch" >> file_1.txt
!git add file_1.txt
!git commit -m 'modify file_1.txt in master branch'
[master 8dad788] modify file_1.txt in master branch
1 file changed, 1 insertion(+)
[11]:
!head file_1.txt
line 1 in file_1.txt in master branch
[12]:
!git log --oneline --decorate
8dad788 (HEAD -> master) modify file_1.txt in master branch
258cd0d create file_2.txt
061eaf7 (testing) create file_1.txt
Cambio a la rama testing
#
[13]:
!git checkout testing
Switched to branch 'testing'
[14]:
!ls -1
file_1.txt
[15]:
!head file_1.txt
Creación de un nuevo archivo en la rama testing
#
[16]:
!touch file_3.txt
!git add file_3.txt
!git commit -m 'create file_3.txt'
[testing a5493a3] create file_3.txt
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 file_3.txt
[17]:
!ls -1
file_1.txt
file_3.txt
[18]:
!git log --oneline --decorate
a5493a3 (HEAD -> testing) create file_3.txt
061eaf7 create file_1.txt
Modificación de un archivo en la rama testing
#
[19]:
!echo "line 1 in file_1.txt in testing branch" >> file_1.txt
!git add file_1.txt
!git commit -m 'modify file_1.txt in testing branch'
[testing 763e66c] modify file_1.txt in testing branch
1 file changed, 1 insertion(+)
[20]:
!git log --oneline --decorate
763e66c (HEAD -> testing) modify file_1.txt in testing branch
a5493a3 create file_3.txt
061eaf7 create file_1.txt
Cambios#
[21]:
!git log --oneline --decorate --graph --all
* 763e66c (HEAD -> testing) modify file_1.txt in testing branch
* a5493a3 create file_3.txt
| * 8dad788 (master) modify file_1.txt in master branch
| * 258cd0d create file_2.txt
|/
* 061eaf7 create file_1.txt
Cambio a la rama master
#
[22]:
!git checkout master
Switched to branch 'master'
[23]:
!ls -1
file_1.txt
file_2.txt
[24]:
!head file_1.txt
line 1 in file_1.txt in master branch
[25]:
# --< Limpieza del área de trabajo >-------------------------------------------
%cd ..
!rm -rf git-demo
/workspace/git