gitGraph commit id: "Initial commit"
git
and GitLab, Pt. 2
Hochschule für Musik, Theater und Medien – Hannover
Institut für Musikphysiologie und Musiker-Medizin
2025-05-26
git
Workflow—A Worked Examplegit
Usage (1)Open a Terminal
testuser@mac3:~$
mkdir testrepo
cd testrepo/
testuser@mac3:~/testrepo$
git init -b main
Leeres Git-Repository in /home/testuser/testrepo/.git/ initialisiert
git status
git
Usage (2)Open your favorite text editor
Windows | MacOS | Linux |
---|---|---|
notepad | BBedit | gedit |
Notepad++ | UltraEdit | nano |
VS Code | VS Code | emacs |
Positron | RStudio | vim |
Positron | VS Code | |
RStudio | ||
Positron |
Don’t use MS Word, LibreOffice et al.
git
Usage (3)Type the following into the text editor
This is the first file of my project
Version: 1
and save the file as my_firstfile.txt in the Working Directory you just created for your project (~/testrepo); close the editor
Note
The file is now in your Working Directory.
This is the file you change if you edit it
(this sounds awfully trivial now but will become important later on).
git
Usage (4)In the Terminal type:
git status
Auf Branch main
Noch keine Commits
Unversionierte Dateien:
(benutzen Sie "git add <Datei>...", um die Änderungen zum Commit vorzumerken)
my_firstfile.txt
nichts zum Commit vorgemerkt, aber es gibt unversionierte Dateien
(benutzen Sie "git add" zum Versionieren)
git status
shows the difference between the Staging Area and the Repository
git
Usage (5)In the Terminal, type:
git add my_firstfile.txt
Note
The file has been added to the Staging Area (Index) and git will detect any changes made to it from now on.
git status
git
Usage (6)To commit all files in the Staging Area to the Repository, type:
git commit -m "Initial commit"
gitGraph commit id: "Initial commit"
Note
The Local Repository now contains a snapshot of the file along with a timestamp and the message “Initial commit”, describing the ‘reason’ for snapshooting.
The commit message will later make the identification of snapshots easier.
git status
git
Usage (7)gitGraph commit id: "Initial commit"
Version: 1
to read Version: 2
git status
git add my_firstfile.txt
git commit -m "Bump version _in file_"
gitGraph commit id: "Initial commit" commit id: "Bump version"
git status
and git show
to investigate repogit
Usage (8)Workflow-centered view
--- config: look: handDrawn --- flowchart LR mkdir["Create Working Directory<br>mkdir ~/testrepo"] --> cd["Change into Working Directory<br>cd ~/testrepo"] cd --> gitinit["Create Local Repository<br>git init"] gitinit --> nano["Create/change file<br>nano my_firstfile.txt"] nano --> gitadd["Add to Staging Area (Index)<br>git add my_firstfile.txt"] gitadd --> nano gitadd --> gitcommit["Commit staged changes to Local Repository<br>git commit -m 'Initial commit'"] gitcommit --> nano
git
-centered view (modeled after https://www.baeldung.com/ops/git-guide)
block-beta columns 2 block columns 3 local["Local Repository"]:3 wdt["Working Directory"] idxt["Staging Index"] lrt["Commit History"] space:2 gitclonedotId1((" ")) gitaddId((" ")) -- "git add" --> gitadddotId((" ")) space space:3 space gitadddotId --> gitcommitId((" ")) gitcommitId -- "git commit" --> gitcommitdotId((" ")) style local stroke-width:0px,fill:#fefbe0; style gitaddId stroke-width:0px,fill:#fefbe0; style gitcommitId stroke-width:0px,fill:#fefbe0; style gitcommitdotId stroke-width:0px,fill:#fefbe0; style gitadddotId stroke-width:0px,fill:#fefbe0; style gitclonedotId1 stroke-width:0px,fill:#fefbe0; end
cat ~/.ssh/id_rsa.pub
ssh -T git@gitlab.gwdg.de
ssh -T git@gitlab.com
git
Usage (9)gitGraph commit id: "Initial commit" commit id: "Bump version"
git remote add origin git@gitlab.gwdg.de:<your-gitlab-handle>/testrepo.git
1git push --set-upstream origin main
git
Usage (10)gitGraph commit id: "Initial commit" commit id: "Bump version"
git pull
(fetches & merges remote w/ local current branch)git show
git checkout -b test <commit-hash>
(create new branch test from commit)gitGraph commit id: "Initial commit" commit id: "Bump version" branch test
git status
git
Usage (11)gitGraph commit id: "Initial commit" commit id: "Bump version" branch test
git add my_firstfile.txt
(add changes to index of branch test)git commit -m "Edit file"
(commit to branch test)gitGraph commit id: "Initial commit" commit id: "Bump version" branch test checkout test commit id: "Edit file"
git
Usage (12)gitGraph commit id: "Initial commit" commit id: "Bump version" branch test checkout test commit id: "Edit file"
git push origin test
(provide new remote branch name)git checkout main
(return to main branch)git pull
(sync with remote main branch)git
Usage (13)gitGraph commit id: "Initial commit" commit id: "Bump version" branch test checkout test commit id: "Edit file"
git merge test
(merge everything in branch test w/ branch main—implies a commit)gitGraph commit id: "Initial commit" commit id: "Bump version" branch test checkout test commit id: "Edit file" checkout main merge test tag: "First merge"
git push
(push everything online, i.e. publish)Thank you for your attention!
IMMM 2025