GIT Setup für CPA Repositories
Sinnvolle .gitconfig Einträge
[user]
name = Mein Name
email = u.name@cp-solutions.at
[alias]
redo-commit = reset --soft HEAD^
st = status -sb
resethard = reset HEAD --hard
stash-all = stash save --include-untracked
glog = log --graph --pretty=format:'%C(yellow)%h%Creset -%C(magenta)%d%Creset %<(80,trunc)%s %Cgreen(%cd) %C(bold blue)<%an>%Creset' --date='format-local:%Y-%m-%d %H:%M'
qm = log -p -w --cc --grep
[core]
commentChar = ";"
[status]
showUntrackedFiles = all
[pull]
rebase = true
[fetch]
prune = true
pruneTags = true
[merge]
conflictStyle = zdiff3
tool = vsdiffmerge
[mergetool "vsdiffmerge"]
cmd = "C:/Program Files/Microsoft Visual Studio/2022/Enterprise/Common7/IDE/CommonExtensions/Microsoft/TeamFoundation/Team Explorer/vsdiffmerge.exe" "$REMOTE" "$LOCAL" "$BASE" "$MERGED" //m
keepbackup = false
trustexitcode = true
Als Befehle zum Konfigurieren
git config --global pull.rebase true
git config --global user.name "Firstname Lastname"
git config --global user.email "i.lastname@cp-solutions.at"
Git Credential Manager
Damit der Zugriff über HTTPS in git funktioniert, müssen die Endpoints für den Git Credential Mananger konfiguriert werden. Dazu folgenden Abschnitt in der .gitconfig anpassen oder hinzufügen:
[credential "https://source.cp-austria.at"]
provider = generic
oauthAuthorizeEndpoint = "/git/login/oauth/authorize"
oauthTokenEndpoint = "/git/login/oauth/access_token"
Siehe auch git-credential-manager Issue 1650
Windows ssh client mit git einrichten
- ssh-agent Service aktivieren
Set-Service ssh-agent -StartupType Automatic
Start-Service ssh-agent
- Neuen ssh key generieren
# Generate key
ssh-keygen -t ed25519
# Add key to ssh-agent
ssh-add
- ssh key in gitea hinterlegen
%USERPROFILE%\.ssh\id_ed25519.pub öffnen und Inhalt kopieren.
In gitea auf Settings / SSH / GPG Keys navigieren und Add Key drücken. Den Inhalt von id_id25519.pub unter Content einfügen und mit Add Key Button speichern.
- git ssh konfigurieren
# tell git to use ssh.exe
git config --global core.sshCommand "'C:\\Windows\\System32\\OpenSSH\\ssh.exe'"
- git remote Url ändern von https auf git
Bei bestehenden Repositories kann die Url geänder werden, z.B. für dplus Repository
git remote set-url origin git@git.cp-austria.at:CPA/dplus.git
In gitea kann bei Clone Menü (<> Code Button) auf ssh umgeschalten werden, um statt der https die ssh url anzuzeigent
Typische Befehle
Aktuelle Checkins vom Server holen
git pull
Neue Datei zum Index hinzufügen
git add path/to/file
Chunks einer Datei zum Index hinzufügen
git add -p [path/to/file]
Änderungen lokal committen
git commit -m "Message"
Lokale Commits zum Server übertragen
git push
git Prompt
wget -O ~/.git-prompt.sh https://github.com/git/git/raw/1eaabe34fc6f486367a176207420378f587d3b48/contrib/completion/git-prompt.sh
In .bashrc git-prompt laden:
if [ -f "${HOME}/.git-prompt.sh" ]; then
source ${HOME}/.git-prompt.sh
fi
Und PS1 Variable in .bashrc anpassen, damit __git_ps1 aufgerufen wird:
PS1='${debian_chroot:+($debian_chroot)}\[\033[32m\]\u@\h \[\033[33m\]\w\[\033[35m\]$(__git_ps1 " (%s)")\[\033[0m\]\$ '
Git Check-in to Tag
# Hole alle Tags
git fetch --tags
# Checke einen aus
git checkout 50600
# Änderungen machen, dann neu taggen (-f, da der Name schon existiert)
git tag 50600 -f
# Pushen mit der Angabe, wohin genau. -f wieder für force
git push origin refs/tags/50600 -f