Gestión de ramas#
Última modificación: Mayo 14, 2022
Preparación del proyecto#
[1]:
!rm -rf git-demo
!mkdir git-demo
%cd git-demo
/workspace/git/git-demo
[2]:
!git init
!git config user.email "you@example.com"
!git config user.name "john doe"
Initialized empty Git repository in /workspace/git/git-demo/.git/
Creación de las ramas#
[3]:
!touch file_1.txt
!git add file_1.txt
!git commit -m 'create file_1.txt in master branch'
[master (root-commit) d397c5e] create file_1.txt in master branch
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 file_1.txt
[4]:
!git checkout -b testing
!touch file_2.txt
!git add file_2.txt
!git commit -m 'create file_2.txt in testing branch'
Switched to a new branch 'testing'
[testing deb600f] create file_2.txt in testing branch
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 file_2.txt
[5]:
!git checkout -b bad-branch-name
!touch file_3.txt
!git add file_3.txt
!git commit -m 'create file_3.txt in bad-branch-name branch'
Switched to a new branch 'bad-branch-name'
[bad-branch-name a0c7529] create file_3.txt in bad-branch-name branch
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 file_3.txt
[6]:
!git checkout master
!git checkout -b hotfix
!touch file_4.txt
!git add file_4.txt
!git commit -m 'create file_4.txt in hotfix branch'
Switched to branch 'master'
Switched to a new branch 'hotfix'
[hotfix baf1847] create file_4.txt in hotfix branch
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 file_4.txt
[7]:
!git checkout master
Switched to branch 'master'
[8]:
!git merge hotfix
Updating d397c5e..baf1847
Fast-forward
file_4.txt | 0
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 file_4.txt
Gestión#
[9]:
# Lista las ramas e indica cual está activa
!git branch
bad-branch-name
hotfix
* master
testing
[10]:
# verbose
!git branch -v
bad-branch-name a0c7529 create file_3.txt in bad-branch-name branch
hotfix baf1847 create file_4.txt in hotfix branch
* master baf1847 create file_4.txt in hotfix branch
testing deb600f create file_2.txt in testing branch
[11]:
!git branch --merged
hotfix
* master
[12]:
!git branch --no-merged
bad-branch-name
testing
[13]:
!git branch --move bad-branch-name corrected-branch-name
[14]:
!git branch -v
corrected-branch-name a0c7529 create file_3.txt in bad-branch-name branch
hotfix baf1847 create file_4.txt in hotfix branch
* master baf1847 create file_4.txt in hotfix branch
testing deb600f create file_2.txt in testing branch
[15]:
!git branch --move master main
!git branch -v
corrected-branch-name a0c7529 create file_3.txt in bad-branch-name branch
hotfix baf1847 create file_4.txt in hotfix branch
* main baf1847 create file_4.txt in hotfix branch
testing deb600f create file_2.txt in testing branch
[16]:
!git branch --all
corrected-branch-name
hotfix
* main
testing
[17]:
# --< Limpieza del área de trabajo >-------------------------------------------
%cd ..
!rm -rf git-demo
/workspace/git