Git signing

Get git signing key ID:

# get keys
gpg --list-secret-keys --keyid-format SHORT

# key id is the one after rsa4096
rsa4096/XXXXXXXX

Setup .gitconfig to sign automatically:

.gitconfig
[user]
	useConfigOnly = true
    email = ...
    signingkey = <XXXXXXXX>

[commit]
    gpgSign = true

[tag]
    gpgSign = true

ref: https://git-scm.com/book/ms/v2/Git-Tools-Signing-Your-Work
ref: https://withblue.ink/2020/05/17/how-and-why-to-sign-git-commits.html

Git diff(ing): Generating and Applying code patches

# GENERATING

# head -1 
git format-patch -1 HEAD

# head - 3 to head
git format-patch HEAD~3..HEAD

# generating a single patch across multiple commits
git format-patch cc1dde0dd^..6de6d4b06 --stdout > foo.patch

# generating diff from tags (can use --stat to only get the number of lines changed)
git diff 2.0.0 1.0.0 --stat

# generating patches for uncommited changes
git diff > my-changes.patch


# APPLYING
git apply <patch-file>

ref: https://www.geeksforgeeks.org/how-to-generate-and-apply-patches-with-git/

Using linux diff command

Can also be done from linux diff commands directly:

# GENERATING
# new code has the new changes we want to make as part of the patch
diff -ru <old code> <new code> > mychanges.patch

# APPLYING
# need to be in the directory in which you want to make the diff changes from
patch -i mychanges.patch

Encrypted git repos

Tbd

Git Archiving Repositories

ghorg

Quickly clone or backup an entire org/users repositories into one directory - Supports GitHub, GitLab, Bitbucket, and more 🐇🥚

Manually

# need to modify if other 100 repos
curl -H "Authorization: Bearer $GITHUB_TOKEN" \
	-H "Content-Type: application/json" \
	-X POST https://api.github.com/graphql \
	-d '{"query": "query { viewer { repositories (first: 100, ownerAffiliations: OWNER) { nodes { sshUrl } } } }"}' \
| jq -r '.data.viewer.repositories.nodes[].sshUrl' \
| xargs -L1 git clone --mirror

May also want to consider –mirror to copy as bare repository with all branches, ideal as a backup or archive as its more compact (compressed) but with no working tree so can’t directly work on it.

Git Convetional Commits

See versioning