Flujo básico de trabajo#

  • Última modificación: Mayo 14, 2022

Creación de la carpeta de trabajo#

[1]:
!mkdir git-demo
%cd git-demo
/workspace/git/git-demo

Inicialización del repositorio#

[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"

Esquema del flujo de trabajo#

assets/git-00002.png

Estado del repositorio#

[4]:
!git status
On branch master

No commits yet

nothing to commit (create/copy files and use "git add" to track)

Creación de un archivo#

Working                   Staging                   .git
Tree                      Area                      directory
-------------------------------------------------------------------------------
[5]:
!touch file_1.txt
!git status
On branch master

No commits yet

Untracked files:
  (use "git add <file>..." to include in what will be committed)
        file_1.txt

nothing added to commit but untracked files present (use "git add" to track)
Working                   Staging             .git
Tree                      Area                directory
-------------------------------------------------------------------------------
file_1.txt
  (empty)

Staging del nuevo archivo#

[6]:
!git add file_1.txt
!git status
On branch master

No commits yet

Changes to be committed:
  (use "git rm --cached <file>..." to unstage)
        new file:   file_1.txt

Working                   Staging                   .git
Tree                      Area                      directory
-------------------------------------------------------------------------------
file_1.txt                file_1.txt
  (empty)                   (empty)

Cambios en el nuevo archivo#

[7]:
!echo 'hello world' > file_1.txt
!git status
On branch master

No commits yet

Changes to be committed:
  (use "git rm --cached <file>..." to unstage)
        new file:   file_1.txt

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        modified:   file_1.txt

Working                   Staging                   .git
Tree                      Area                      directory
-------------------------------------------------------------------------------
file_1.txt                file_1.txt
  hello world               (empty)

Staging de los nuevos cambios#

[8]:
!git add file_1.txt
!git status
On branch master

No commits yet

Changes to be committed:
  (use "git rm --cached <file>..." to unstage)
        new file:   file_1.txt

Working                   Staging                   .git
Tree                      Area                      directory
-------------------------------------------------------------------------------
file_1.txt                file_1.txt
  hello world               hello world

Commit#

[9]:
!git commit -m 'create file_1.txt'
[master (root-commit) a35cdbe] create file_1.txt
 1 file changed, 1 insertion(+)
 create mode 100644 file_1.txt
Working                   Staging                   .git
Tree                      Area                      directory
-------------------------------------------------------------------------------
file_1.txt                                          file_1.txt
  hello world                                         hello world

Borrado del archivo#

[10]:
!rm file_1.txt
Working                   Staging                   .git
Tree                      Area                      directory
-------------------------------------------------------------------------------
                                                    file_1.txt
                                                      hello world

Restauración del archivo#

[11]:
!git checkout -- file_1.txt
Working                   Staging                   .git
Tree                      Area                      directory
-------------------------------------------------------------------------------
file_1.txt                                          file_1.txt
  hello world                                         hello world
[12]:
!cat file_1.txt
hello world
[13]:
# --< Limpieza del área de trabajo >-------------------------------------------
%cd ..
!rm -rf git-demo
/workspace/git