Seltene git-Probleme lösen

(, de)

origin verändern

git remote set-url origin ...
# HTTPS
git remote set-url origin https://...
# SSH
git remote set-url origin git@...

Branch Alias anlegen

git symbolic-ref refs/heads/acc refs/heads/acceptance

Umlaute (non-ASCII) in git status

git config --global core.quotePath false

Quelle

git merge Konflikte lösen

git format-patch -10 HEAD --stdout > 0001-last-10-commits.patch
git format-patch commitx..HEAD --stdout > 0001-commits.patch
git apply 0001-commits.patch

Upstream git branch löschen

$ git push <remote_name> --delete <branch_name>
# or
$ git push <remote_name> :<branch_name>

Quelle

Commit-Datum anpassen

DATE="$(date +%F) 17:10:35"
GIT_COMMITTER_DATE=$DATE GIT_AUTHOR_DATE=$DATE git commit -a

Reset des letzten Commits, Änderungen behalten

git reset --soft HEAD~1
git reset --soft HEAD^

HTTPS-Authentifizierung über Umgebungsvariablen

# Makefile

# authenticate to https resource using environment variables (e.g. in CI/CD pipelines)
# taken from https://git-scm.com/docs/gitcredentials, `$$` escapes `$`
git-setup: ## set up git credentials for authentication
	git config --global credential.helper '!f() { [ "$$1" = "get" ] && echo "username=$${APP_USER}" && echo "password=$${APP_PASSWORD}"; }; f'
	git config --global user.email "app@@example.de"
	git config --global user.name "app"

Datei in git und nicht im working dir löschen

git rm --cached file_to_remove.txt

Merge Unrelated Histories

git pull origin main --allow-unrelated-histories

Quelle

Fehler: cannot lock existing

git pull
error: cannot lock existing
git remote prune origin

Git and nasty “error: cannot lock existing info/refs fatal” - Stack Overflow