Skip to content

Instantly share code, notes, and snippets.

@larry0x
Last active February 11, 2024 17:00
Show Gist options
  • Save larry0x/641c3cfacc5cbfb738be2be484852000 to your computer and use it in GitHub Desktop.
Save larry0x/641c3cfacc5cbfb738be2be484852000 to your computer and use it in GitHub Desktop.

Configure gpg signing (importing an existing private key):

git config --global user.name 'your-name'
git config --global user.email 'your-email'
git config --global user.signingkey 'your-gpg-pubkey'
git config --global commit.gpgsign true
git config --global --list

sudo apt install gpg
gpg --import /path/to/private/key/file
gpg --list-secret-keys --keyid-format long

# necessary for it to work. see:
# https://gist.github.com/paolocarrasco/18ca8fe6e63490ae1be23e84a7039374?permalink_comment_id=3767413#gistcomment-3767413
export GPG_TTY=$(tty)

Delete all branches except for main:

git branch | grep -v 'main' | xargs git branch -D

Delete all tags:

git tag | xargs git tag -d

Soft reset the initial commit

git update-ref -d HEAD

Copy contents from another repository, keep commit history

git remote add source /path/to/source/repo
git fetch source
git merge source/main --allow-unrelated-histories
git remote remove source

Fetch a single tag from remote (https://stackoverflow.com/a/54635270):

git fetch source tag v0.31.1 --no-tags

Clone a repo including all its submodules recursively (https://stackoverflow.com/a/4438292):

git clone --recurse-submodules -j8 git://github.com/foo/bar.git
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment