Unterschiede
Hier werden die Unterschiede zwischen zwei Versionen angezeigt.
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.1 | git_gitea [25/04/2025 - 09:09] (aktuell) – [Remote Repos] thommie_netzwissen.de | ||
---|---|---|---|
Zeile 1: | Zeile 1: | ||
+ | ====== GIT und GITHUB Basisdoku ====== | ||
+ | |||
+ | * [[https:// | ||
+ | * [[https:// | ||
+ | * [[https:// | ||
+ | * [[https:// | ||
+ | |||
+ | ===== Basisfunktionen & lokale Instanz ===== | ||
+ | |||
+ | - Arbeitskopie = die echten Dateien, dynamisch | ||
+ | - '' | ||
+ | - '' | ||
+ | - HEAD zeigt immer auf letzten Commit. Ein '' | ||
+ | |||
+ | Initialisierung: | ||
+ | |||
+ | < | ||
+ | git init | ||
+ | git add . | ||
+ | |||
+ | </ | ||
+ | |||
+ | Danach initialer Commit, um den aktuellen Stand im HEAD aufzunehmen | ||
+ | |||
+ | '' | ||
+ | |||
+ | Nachträgliches Ändern eines commit Textes | ||
+ | |||
+ | '' | ||
+ | |||
+ | |||
+ | ===== Remote Repos ===== | ||
+ | |||
+ | " | ||
+ | |||
+ | **Kontrolle der Remote Ziele " | ||
+ | < | ||
+ | git remote -v | ||
+ | |||
+ | origin | ||
+ | origin | ||
+ | upstream | ||
+ | upstream | ||
+ | |||
+ | </ | ||
+ | |||
+ | 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. | ||
+ | * upstream = Master repo, eigene commits landen dort per Pull Request | ||
+ | |||
+ | Aus [[https:// | ||
+ | |||
+ | ===== Fix upstream branch errors with autoSetupRemote ===== | ||
+ | |||
+ | If you constantly run into Git's fatal " | ||
+ | < | ||
+ | |||
+ | This is done by setting the push.autoSetupRemote option in any of [[https:// | ||
+ | |||
+ | ===== How to set push.autoSetupRemote ===== | ||
+ | |||
+ | To tell Git to automatically create new branches in remote repositories upon a push, simply issue the following command: | ||
+ | < | ||
+ | |||
+ | With that configuration setting in place, you'll never have to push with the | ||
+ | < | ||
+ | |||
+ | |||
+ | ===== öffentliche Repos: Kollaboration ===== | ||
+ | |||
+ | Öffentliche Repos werden zunächst geforkt, also eine Kopie im eigenen Repo-Speicher als " | ||
+ | |||
+ | * upstream = öffentliches Github Repo (z.B. [[https:// | ||
+ | |||
+ | Lokale Instanz: hinzufügen des entfernten " | ||
+ | < | ||
+ | |||
+ | git remote add origin git@github.com: | ||
+ | git push -u origin master | ||
+ | |||
+ | </ | ||
+ | |||
+ | Analog geht das Verbinden des öffentlichen Repos als " | ||
+ | |||
+ | < | ||
+ | git remote add upstream '' | ||
+ | |||
+ | </ | ||
+ | |||
+ | ===== Authentifizierung über access token ===== | ||
+ | |||
+ | < | ||
+ | git remote set-url origin https:// | ||
+ | |||
+ | </ | ||
+ | |||
+ | ====== Synchronisation lokales Repo mit entfernten ====== | ||
+ | |||
+ | **pushen** | ||
+ | |||
+ | '' | ||
+ | |||
+ | '' | ||
+ | |||
+ | **abholen** | ||
+ | |||
+ | '' | ||
+ | |||
+ | '' | ||
+ | |||
+ | ===== Github: entferntes Repo klonen ===== | ||
+ | |||
+ | Lokale Kopie des aktuellen Arbeitsstandes auf github anlegen | ||
+ | |||
+ | '' | ||
+ | |||
+ | '' | ||
+ | |||
+ | ===== Update des Fork auf Github ===== | ||
+ | |||
+ | Das geht über das **lokale** | ||
+ | |||
+ | Updates von Upstream holen | ||
+ | |||
+ | < | ||
+ | '' | ||
+ | |||
+ | </ | ||
+ | |||
+ | Zum master bzw. main wechseln | ||
+ | |||
+ | < | ||
+ | '' | ||
+ | |||
+ | </ | ||
+ | |||
+ | Master mit upstream mergen | ||
+ | |||
+ | < | ||
+ | '' | ||
+ | |||
+ | </ | ||
+ | |||
+ | Danach push auf den fork setzen. | ||
+ | |||
+ | ====== Branches ====== | ||
+ | |||
+ | Branch erzeugen | ||
+ | |||
+ | < | ||
+ | git checkout -b iss53 | ||
+ | </ | ||
+ | |||
+ | Wo bin ich (aktueller Branch) | ||
+ | |||
+ | < | ||
+ | git branch | ||
+ | </ | ||
+ | |||
+ | Alle Branches im lokalen und im remote Repo zeigen (remotes) | ||
+ | |||
+ | < | ||
+ | git branch -a | ||
+ | |||
+ | main | ||
+ | * master | ||
+ | remotes/ | ||
+ | remotes/ | ||
+ | remotes/ | ||
+ | </ | ||
+ | |||
+ | Nur die remotes zeigen | ||
+ | |||
+ | < | ||
+ | git branch -r | ||
+ | </ | ||
+ | |||
+ | Zum anderen Branch wechseln | ||
+ | |||
+ | < | ||
+ | git checkout master | ||
+ | </ | ||
+ | |||
+ | Freier Wechsel zu Branch | ||
+ | |||
+ | '' | ||
+ | |||
+ | Lokal erzeugten Branch im remote Repo verfügbar machen | ||
+ | |||
+ | '' | ||
+ | |||
+ | synchronisiert in den Master Branch vom Remote Repo (origin)." | ||
+ | |||
+ | Neuen Branch erstellen und zu diesem wechseln | ||
+ | |||
+ | '' | ||
+ | |||
+ | Branch löschen | ||
+ | |||
+ | '' | ||
+ | |||
+ | ===== Download eines bestimmten Branch ===== | ||
+ | |||
+ | '' | ||
+ | |||
+ | danach | ||
+ | |||
+ | '' | ||
+ | |||
+ | Oder: | ||
+ | |||
+ | '' | ||
+ | |||
+ | ===== Merge & update ===== | ||
+ | |||
+ | '' | ||
+ | |||
+ | Holt Änderungen von Remote (fetch) **und führt sie mit dem lokalen Stand zusammen** | ||
+ | |||
+ | '' | ||
+ | |||
+ | ===== Upstream nach fork mergen ===== | ||
+ | |||
+ | Lokales Ziel | ||
+ | < | ||
+ | |||
+ | git checkout //master// | ||
+ | |||
+ | </ | ||
+ | |||
+ | Welche branch von Upstream soll wohin geholt werden? | ||
+ | |||
+ | < | ||
+ | git pull git@github.com: | ||
+ | |||
+ | </ | ||
+ | |||
+ | Danach commit, review und push auf den fork bei Github | ||
+ | |||
+ | ====== Wenn etwas ganz schiefgeht ====== | ||
+ | |||
+ | '' | ||
+ | |||
+ | setzt die lokalen Änderungen auf den letzten HEAD Stand. Änderungen, | ||
+ | |||
+ | Hard Reset = Zurück auf den letzten Stand vom entfernten Repository: | ||
+ | |||
+ | '' | ||
+ | |||
+ | ====== 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:// | ||
+ | |||
+ | ====== Basis Konfiguration eines Repos ====== | ||
+ | |||
+ | |< | ||
+ | git config -global user.name [name] | ||
+ | |||
+ | git config -global user.email [email] | ||
+ | |||
+ | git config -global core.editor [editor] | ||
+ | |||
+ | </ | ||
+ | |'' | ||
+ | |'' | ||
+ | |'' | ||
+ | |'' | ||
+ | |'' | ||
+ | |'' | ||
+ | |'' | ||
+ | |'' | ||
+ | |'' | ||
+ | |'' | ||
+ | |'' | ||
+ | | | ||
+ | |||
+ | ===== Repo duplizieren ===== | ||
+ | |||
+ | Create a bare clone of the repository. | ||
+ | |||
+ | $ git clone –bare [[https:// | ||
+ | |||
+ | Mirror-push to the new repository. | ||
+ | |||
+ | $ cd old-repository.git $ git push –mirror [[https:// | ||
+ | |||
+ | Remove the temporary local repository you created earlier. | ||
+ | |||
+ | $ cd .. $ rm -rf old-repository.git | ||
+ | |||
+ | ===== Alte commits entfernen ===== | ||
+ | |||
+ | Commits sichten | ||
+ | < | ||
+ | |||
+ | git log --oneline | ||
+ | |||
+ | </ | ||
+ | |||
+ | Neuen Branch erzeugen, aber ohne history (–orphan) | ||
+ | |||
+ | < | ||
+ | git checkout --orphan tem_branch | ||
+ | |||
+ | </ | ||
+ | |||
+ | Alle Files hinzufügen | ||
+ | |||
+ | < | ||
+ | git add -A | ||
+ | |||
+ | </ | ||
+ | |||
+ | Inital commit im neuen Branch | ||
+ | |||
+ | < | ||
+ | git commit -am " | ||
+ | |||
+ | </ | ||
+ | |||
+ | Alten Branch löschen | ||
+ | |||
+ | < | ||
+ | git branch -D main | ||
+ | |||
+ | </ | ||
+ | |||
+ | Den aktuellen Brach umbenennen | ||
+ | |||
+ | < | ||
+ | git branch -m main | ||
+ | < | ||
+ | |||
+ | Den " | ||
+ | |||
+ | < | ||
+ | git push -f origin main | ||
+ | |||
+ | </ | ||
+ | |||
+ | ====== Git mit SSH ====== | ||
+ | |||
+ | Mehrere ssh Key benutzen: | ||
+ | |||
+ | Keys zum agent hinzufügen: | ||
+ | |||
+ | < | ||
+ | < | ||
+ | |||
+ | </ | ||
+ | |||
+ | .ssh/config | ||
+ | |||
+ | < | ||
+ | < | ||
+ | |||
+ | #HostName gitea.netzwissen.de | ||
+ | # IdentityFile ~/ | ||
+ | # User git | ||
+ | |||
+ | Host 192.168.72.12 | ||
+ | IdentityFile ~/ | ||
+ | User thommie | ||
+ | |||
+ | Host kakariki.netzwissen.de | ||
+ | HostName kakariki.netzwissen.de | ||
+ | IdentityFile ~/ | ||
+ | |||
+ | </ | ||
+ | |||
+ | Im Repo selbst | ||
+ | |||
+ | .git/config | ||
+ | |||
+ | < | ||
+ | < | ||
+ | | ||
+ | bare = false | ||
+ | | ||
+ | ** | ||
+ | [remote " | ||
+ | url = ssh:// | ||
+ | fetch = +refs/ | ||
+ | [branch " | ||
+ | | ||
+ | merge = refs/ | ||
+ | |||
+ | </ | ||
+ | |||
+ | ====== Gitea ====== | ||
+ | |||
+ | Git with a cup of tea - A painless self-hosted Git service | ||
+ | |||
+ | [[https:// | ||
+ | |||
+ | [[https:// | ||
+ | |||
+ | [[https:// | ||
+ | |||
+ | Upgrade script: / | ||
+ | |||