Seltene git-Probleme lösen

(, de)

origin verändern

git remote set-url origin ...
git remote set-url origin https://...
git remote set-url origin git@...

Rebase after squashed PR to main

Assume the following history:

                               D---E---F branch2
                     A---B---C branch1
               D---E main

branch1 will be squash-merged:

                               D---E---F branch2
                             ^  tig T commit
               D---E---ABC main

git rebase --onto ABC C branch2 results in

                           D---E---F branch2
               D---E---ABC main

Checkout branch2 and take all commits in my current branch since commit C and play back on top of ABC

SO - How to rebase after squashing commits in the original branch?

Branch Alias anlegen

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

Umlaute (non-ASCII) in git status

git config --global core.quotePath false


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>


Commit-Datum anpassen

DATE="$(date +%F) 17:10:35"

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, `$$` 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 ""
	git config --global "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


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