Linux
HOGENT toegepaste informatica
Thomas Parmentier, Andy Van Maele, Bert Van Vreckem
2024-2025
Gebruik Git vanop de command line
(Tenminste, totdat je begrijpt wat je doet…)
Herhaal dit op elk systeem waar je Git gebruikt!
$ git config --global user.name "VOORNAAM NAAM"
$ git config --global user.email "VOORNAAM.NAAM@EXAMPLE.COM"
$ git config --global push.default simple
$ git config --global pull.rebase true
$ git config --global core.autocrlf input
of
$ git config --global --edit
Voorbeeld: https://github.com/bertvv/dotfiles/blob/main/.gitconfig
Herhaal dit op elk systeem waar je Git gebruikt!
osboxes@osboxes:~$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/home/bert/.ssh/id_rsa):
Created directory '/home/bert/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/bert/.ssh/id_rsa
Your public key has been saved in /home/bert/.ssh/id_rsa.pub
The key fingerprint is:
SHA256:S/WtkPaCSXWK/oqs9lywV6XnMf8nYmYMZ4Io1lx8fS4 bert@osboxes
The key's randomart image is:
+---[RSA 3072]----+
| |
| |
| . o.o |
| o+.B... |
| o.oSoB =o. |
| o +*.*o=E=. |
| . .. B .*+.. |
| .o + . .* ...|
| ..o= ...+ . .o|
+----[SHA256]-----+
~/.ssh/id_rsa.pub
en kopieer de
volledige inhoudPlak in het “Key” veld:
Ga naar Chamilo, volg de link om een Github-repo aan te maken.
https://github.com/HoGentTIN/linux-2122-scripts-USERNAME
Maak repo aan op Github (Classroom)
Lokale kopie maken met
git clone git@github.com:USER/REPO.git
Je hebt nu een lokale kopie van de Github-repo:
~/linux-2122-scripts-USERNAME
.git
Klik “Code”, SSH, Kopieer de URL:
osboxes@osboxes:~$ git clone git@github.com:HoGentTIN/linux-2122-scripts-bertvv.git
Cloning into 'linux-2122-scripts-bertvv'...
The authenticity of host 'github.com (140.82.121.4)' can't be established.
RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added 'github.com,140.82.121.4' (RSA) to the list of known hosts.
remote: Enumerating objects: 28, done.
remote: Counting objects: 100% (28/28), done.
remote: Compressing objects: 100% (25/25), done.
remote: Total 28 (delta 1), reused 27 (delta 1), pack-reused 0
Receiving objects: 100% (28/28), 17.54 KiB | 8.77 MiB/s, done.
Resolving deltas: 100% (1/1), done.
Open terminal in directory met lokale kopie
[Bestanden bewerken]
$ git add .
$ git commit -m "Beschrijving aanpassingen"
git add BESTAND1 BESTAND2 ...
.
= huidige directory (recursief)git status
!Na elke stap, bij twijfel
git pull
of git pull --rebase
git push
Maak een bestand README.md
met deze inhoud:
Commit, push naar Github, bekijk het resultaat op github.com!
$ git push
To github.com:bertvv/git-demo.git
! [rejected] main -> main (fetch first)
error: failed to push some refs to 'git@github.com:bertvv/git-demo.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
$ git pull --rebase
$ git status
rebase in progress; onto e5bd2df
You are currently rebasing branch 'main' on 'e5bd2df'.
(fix conflicts and then run "git rebase --continue")
(use "git rebase --skip" to skip this patch)
(use "git rebase --abort" to check out the original branch)
Unmerged paths:
(use "git reset HEAD <file>..." to unstage)
(use "git add <file>..." to mark resolution)
both modified: README.md
no changes added to commit (use "git add" and/or "git commit -a")
If you have questions, please
<<<<<< HEAD
open an issue
======
ask your question in IRC.
>>>>>> branch-a
$ git add .
$ git status
rebase in progress; onto e5bd2df
You are currently rebasing branch 'main' on 'e5bd2df'.
(all conflicts fixed: run "git rebase --continue")
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
modified: README.md
$ git rebase --continue
$ git status
$ git push
$ git status
git status
!.gitignore
- bepaalde bestanden nooit in versiebeheer
opnemenVoeg toe aan ~/.bashrc
alias gp='git pull --rebase'
alias pr='git pull --rebase'
alias pt='git push -u origin --tags'
# Git author stats
alias gs='git ls-tree -r -z --name-only HEAD | xargs -0 -n1 git blame --line-porcelain | grep "^author "|sort|uniq -c|sort -nr'
Zie: https://github.com/bertvv/dotfiles/blob/main/.bash.d/aliases.sh