git_gitea

Unterschiede

Hier werden die Unterschiede zwischen zwei Versionen angezeigt.

Link zu dieser Vergleichsansicht

Beide Seiten der vorigen Revision Vorhergehende Überarbeitung
Nächste Überarbeitung
Vorhergehende Überarbeitung
git_gitea [01/10/2022 - 10:26] – gelöscht - Externe Bearbeitung (Unknown date) 127.0.0.1git_gitea [05/03/2024 - 10:52] (aktuell) – Externe Bearbeitung 127.0.0.1
Zeile 1: Zeile 1:
 +====== GIT und GITHUB Basisdoku ======
 +
 +  * [[https://rogerdudler.github.io/git-guide/index.de.html|https://rogerdudler.github.io/git-guide/index.de.html]]
 +  * [[https://git-scm.com/docs/everyday|https]][[https://git-scm.com/docs/everyday|://git-scm.com/docs/everyday ]]
 +  * [[https://github.com/yui/yui3/wiki/Set-Up-Your-Git-Environment|https://github.com/yui/yui3/wiki/Set-Up-Your-Git-Environment ]]
 +  * [[https://www.thomas-krenn.com/de/wiki/Git_Grundbefehle|https://www.thomas-krenn.com/de/wiki/Git_Grundbefehle]]
 +
 +===== Basisfunktionen & lokale Instanz =====
 +
 +  - Arbeitskopie = die echten Dateien, dynamisch
 +  - ''git add''  addiert den aktuellen Datenstand in den Index ("Stage")
 +  - ''git coomit''  trägt den Datenstand in den HEAD ein (standardmässig in den "main" Branch)
 +  - HEAD zeigt immer auf letzten Commit. Ein ''git commit -m "Commit-Nachricht"''  übernimmt den Status nach HEAD.
 +
 +Initialisierung: leeres Repository erzeugen und die darin vorhandenen Dateien in den lokalen git Index aufnehmen
 +<code>
 +
 +git init
 +git add .
 +
 +</code>
 +
 +Danach initialer Commit, um den aktuellen Stand im HEAD aufzunehmen
 +
 +''git commit -m "Commit-Nachricht"''
 +
 +===== Remote Repos: Verknüpfen einer lokalen Instanz mit Remote Instanzen =====
 +
 +"origin" ist das **eigene**  Standard-remote-Repo (z.B. github, gitea). "upstream" ist das Team-Repo. Änderungen aus "origin" werden mit einem Pull Request für das "upstream" Repo angeboten. Von dort wird die Änderungen per "pull" geholt, falls sie akzeptiert wird.
 +
 +**Kontrolle der Remote Ziele "origin" und "upstream"**
 +
 +<code>
 +git remote -v
 +
 +origin  git@github.com:thommierother/docs.git (fetch)
 +origin  git@github.com:thommierother/docs.git (push)
 +upstream        git@github.com:owncloud/docs.git (fetch)
 +upstream        git@github.com:owncloud/docs.git (push)
 +
 +</code>
 +
 +Nach dem Anlegen eines eigenen Repos auf github kann man das lokale Repo mit einem Repo auf github verknüpfen.
 +
 +  * origin = persönliches git Repo auf Github. Die kann ein privater Fork eines öffentlichen Repos auf github sein.
 +
 +Anders bei öffentlichen Repos: Öffentliche Repos werden zunächst geforkt, also eine Kopie im eigenen Repo-Speicher als "origin" angelegt. Lokale Änderungen werden zuerst nach origin übertragen. Danach werden sie per pull request (PR) zur Übernahme nach upstream "angemeldet".
 +
 +  * upstream = öffentliches Github Repo (z.B. [[https://github.com/owncloud/core|https://github.com/owncloud/core]]).
 +
 +Lokale Instanz: hinzufügen des entfernten "origin"
 +<code>
 +
 +git remote add origin git@github.com:thommierother/oc-theme-nw2.git
 +git push -u origin master
 +
 +</code>
 +
 +Analog geht das Verbinden des öffentlichen Repos als "upstream":
 +
 +<code>
 +git remote add upstream ''git@github.com:https://github.com/owncloud/docs.git''
 +
 +</code>
 +
 +===== Authentifizierung über access token =====
 +
 +<code>
 +git remote set-url origin https://username:token@github.com/username/repository.git
 +
 +</code>
 +
 +====== Synchronisation lokales Repo mit entfernten ======
 +
 +**pushen**
 +
 +''git push origin''  Änderungen auf das eigene Repo oder auf den Fork **senden**
 +
 +''git push upstream ''Änderungen nach upstream **senden**
 +
 +**abholen**
 +
 +''git fetch origin''  Änderungen vom eigenen Repo oder vom Fork eines öffentlichen Repos abholen
 +
 +''git fetch upstream ''Änderungen von upstream abholen
 +
 +===== Github: entferntes Repo klonen =====
 +
 +Lokale Kopie des aktuellen Arbeitsstandes auf github anlegen
 +
 +''git clone /pfad/zum/''''repository''
 +
 +''git commit -m "Commit-Nachricht''  Änderungen hochladen
 +
 +===== Update des Fork auf Github =====
 +
 +Das geht über das **lokale**  Repo:
 +
 +Updates von Upstream holen
 +
 +<code>
 +''$ git fetch upstream''
 +
 +</code>
 +
 +Zum master bzw. main wechseln
 +
 +<code>
 +''git checkout master''
 +
 +</code>
 +
 +Master mit upstream mergen
 +
 +<code>
 +''git merge upstream/master''
 +
 +</code>
 +
 +Danach push auf den fork setzen.
 +
 +====== Branches ======
 +
 +Wo bin ich (aktueller Branch)
 +
 +<file>
 +git branch
 +
 +</file>
 +
 +Alle Branches im lokalen und im remote Repo zeigen (remotes)
 +
 +<code>
 +git branch -a
 +
 +  main
 +* master
 +  remotes/origin/HEAD -> origin/main
 +  remotes/origin/main
 +  remotes/origin/master
 +
 +</code>
 +
 +Zum anderen Branch wechseln
 +
 +<code>
 +git checkout master
 +
 +</code>
 +
 +Freier Wechsel zu Branch
 +
 +''git checkout [branchname]''
 +
 +Lokal erzeugten Branch im remote Repo verfügbar machen
 +
 +''git push origin master ''
 +
 +synchronisiert in den Master Branch vom Remote Repo (origin)."origin" weist auf den (privaten) Fork eines Github-zentralen Repos.
 +
 +Neuen Branch erstellen und zu diesem wechseln
 +
 +''git checkout -b feature_x''
 +
 +Branch löschen
 +
 +''git branch -d feature_x''
 +
 +===== Download eines bestimmten Branch =====
 +
 +''git checkout -b workstation-16.2.1 origin/workstation-16.2.1''
 +
 +danach
 +
 +''git pull''
 +
 +Oder:
 +
 +''git clone -b workstation-17.0.2 [[https://github.com/mkubecek/vmware-host-modules.git|https://github.com/mkubecek/vmware-host-modules.git]]''
 +
 +===== Merge & update =====
 +
 +''git pull''
 +
 +Holt Änderungen von Remote (fetch) **und führt sie mit dem lokalen Stand zusammen**  (merge). Bei Konflikten: Dateien manuell korrigieren und danach die geänderte Datei mit ''git add [dateiname]''  einbauen. Die Unterschiede sieht man mit
 +
 +''git diff <quell_branch> <ziel_branch>''
 +
 +===== Upstream nach fork mergen =====
 +
 +Lokales Ziel
 +<code>
 +
 +git checkout //master//
 +
 +</code>
 +
 +Welche branch von Upstream soll wohin geholt werden?
 +
 +<file>
 +git pull git@github.com:owncloud/docs.git BRANCH_NAME
 +
 +</file>
 +
 +Danach commit, review und push auf den fork bei Github
 +
 +====== Wenn etwas ganz schiefgeht ======
 +
 +''git checkout – ''
 +
 +setzt die lokalen Änderungen auf den letzten HEAD Stand. Änderungen, die du bereits zum Index hinzugefügt hast, bleiben bestehen.
 +
 +Hard Reset = Zurück auf den letzten Stand vom entfernten Repository:
 +
 +''git fetch origin''  ''git reset –hard origin/master''
 +
 +====== Pull requests ======
 +
 +Pull requests let you tell others about changes you've pushed to a branch in a repository on GitHub. Once a pull request is opened, you can discuss and review the potential changes with collaborators and add follow-up commits before your changes are merged into the base branch.
 +
 +[[https://www.digitalocean.com/community/tutorials/how-to-create-a-pull-request-on-github|https://www.digitalocean.com/community/tutorials/how-to-create-a-pull-request-on-github]]
 +
 +====== Basis Konfiguration eines Repos ======
 +
 +|<file>
 +git config -global user.name [name]
 +
 +git config -global user.email [email]
 +
 +git config -global core.editor [editor]
 +
 +</file>       |**GIT User Konfiguration setzen**   |
 +|''git config -l ''   |**Konfiguration zeigen**   |
 +|''git status ''   |**zeigt,ob eine Datei editiert wurde**   |
 +|''git-diff and git-status ''   |**Show the working tree status**   |
 +|''git commit ''   |**Änderungen einspielen**   |
 +|''git checkout -b branch2 ''   |**Wechsel zwischen Branches: Neuen Branch erstellen und dort hin wechseln**   |
 +|''git-reset[1] ''   |**Reset current HEAD to the specified state**   |
 +|''git-merge ''   |**Join two or more development histories together**   |
 +|''git-rebase ''   |**Reapply commits on top of another base tip**   |
 +|''git tag ''   |**Tags zeigen (z.B. einzelne Releases)**   |
 +|''git log ''   |**Letzte Commits zeigen**   |
 +|''git fetch <remote>''   |**Objektstruktur runterladen**   |
 +|     |
 +
 +===== Repo duplizieren =====
 +
 +Create a bare clone of the repository.
 +
 +$ git clone –bare [[https://github.com/exampleuser/old-repository.git|https://github.com/exampleuser/old-repository.git]]
 +
 +Mirror-push to the new repository.
 +
 +$ cd old-repository.git $ git push –mirror [[https://github.com/exampleuser/new-repository.git|https://github.com/exampleuser/new-repository.git]]
 +
 +Remove the temporary local repository you created earlier.
 +
 +$ cd .. $ rm -rf old-repository.git
 +
 +===== Alte commits entfernen =====
 +
 +Commits sichten
 +<code>
 +
 +git log --oneline
 +
 +</code>
 +
 +Neuen Branch erzeugen, aber ohne history (–orphan)
 +
 +<code>
 +git checkout --orphan tem_branch
 +
 +</code>
 +
 +Alle Files hinzufügen
 +
 +<code>
 +git add -A
 +
 +</code>
 +
 +Inital commit im neuen Branch
 +
 +<code>
 +git commit -am "Initial commit message"
 +
 +</code>
 +
 +Alten Branch löschen
 +
 +<code>
 +git branch -D main
 +
 +</code>
 +
 +Den aktuellen Brach umbenennen
 +
 +<code>
 +git branch -m main
 +<code>
 +
 +Den "zurückgesetzten" main Branch aufs remote laden
 +
 +<code>
 +git push -f origin main
 +
 +</code>
 +
 +====== Git mit SSH ======
 +
 +Mehrere ssh Key benutzen:
 +
 +Keys zum agent hinzufügen:
 +
 +<code>
 + <font inherit/monospace;;inherit;;#000000background-color:#ffffff;>ssh-add ~/.ssh/id_rsa3</font>
 +
 +</code>
 +
 +.ssh/config
 +
 +<code>
 + <font inherit/monospace;;inherit;;#000000background-color:#ffffff;>Host gitea gitea.netzwissen.de</font>      ForwardAgent yes
 +
 +#HostName gitea.netzwissen.de
 +# IdentityFile ~/.ssh/id_rsa_gitea
 +# User git
 +
 +Host 192.168.72.12
 +IdentityFile ~/.ssh/id_rsa
 +User thommie
 +
 +Host kakariki.netzwissen.de
 +HostName kakariki.netzwissen.de
 +IdentityFile ~/.ssh/id_rsa3
 +
 +</code>
 +
 +Im Repo selbst
 +
 +.git/config
 +
 +<code>
 + <font inherit/monospace;;inherit;;#000000background-color:#ffffff;>[core]</font>           repositoryformatversion = 0
 +       filemode = true
 +       bare = false
 +       logallrefupdates = true
 +**       sshCommand = ssh -i ~/.ssh/id_rsa**
 +[remote "origin"]
 +       url = ssh://git@gitea.netzwissen.de:2022/thommie/thommievault.git
 +       fetch = +refs/heads/*:refs/remotes/origin/*
 +[branch "main"]
 +       remote = origin
 +       merge = refs/heads/main
 +
 +</code>
 +
 +
 +====== Gitea ======
 +
 +Git with a cup of tea - A painless self-hosted Git service
 +
 +[[https://gitea.io/en-us/|https://gitea.io/en-us/]]
 +
 +[[https://dl.gitea.io/gitea/xxx/gitea-xxx-linux-arm64|https://dl.gitea.io/gitea/xxx/gitea-xxx-linux-arm64]]
 +
 +[[https://docs.gitea.io/en-us/upgrade-from-gitea/|https://docs.gitea.io/en-us/upgrade-from-gitea/]]
 +
 +Upgrade script: /etc/scripts/gitea_upgrade.sh
 +