Skip to content

GIT

Something Strange is Going On, Let's just Reset Everything

git reset --hard; git pull --rebase; git fsck --full; git gc --auto

Pull ALL THE THINGS

Example

git branch -r | grep -v '\->' | sed "s,\x1B\[[0-9;]*[a-zA-Z],,g" | while read remote; do git branch --track "${remote#origin/}" "$remote"; done
git fetch --all
git pull --all

Clone a Bare Repo, Useful for Hosting

git clone --bare --mirror --shared URI-TO-REPO

If you're hosting mirrors that are done as bare repos, then you should update. This makes sure you're getting all the branches and updates. Drop this into a cron and let it run.

#!/usr/bin/env bash
cd /srv/git || exit 1
for x in $(echo *.git); do
        cd "${x}"
        echo "Updating ${x}"
        git remote update
        git --bare fetch --all
        git --bare fetch origin *:*
        cd ..
done

Convert a Repo to Bare - Useful when a Big Oopsie Happens

Example

cd repo
mv .git ../repo.git # renaming just for clarity
cd ..
rm -fr repo
cd repo.git
git config --bool core.bare true

Git Commits failing to Sign

This most likely happens when pin entry is broken

When pinentry-mac is most likely broken

brew upgrade gnupg
brew link --overwrite gnupg
brew install pinentry-mac
echo "pinentry-program /opt/homebrew/bin/pinentry-mac" >> ~/.gnupg/gpg-agent.conf
killall gpg-agent