Git

| Comments

Contents:

Commands #

Cleanup a local repository of all untracked files:

git clean -dfx

Throw away all uncommitted changes:

git reset --hard HEAD

Large files support #

Resources:

Installation:

brew install git-lfs

In the git repository:

git lfs install

To add file extensions to track via “lfs”:

git lfs track "*.psd"

git-sync #

Git repos with different SSH key for authentication & signing #

Let’s say we have this non-default identity file: ~/.ssh/id_corp.pub

All commands below are run with plain git config (no --global), so they apply only the repository’s .git/config (in the current directory).

Commit signing #

git config user.signingKey "$(cat ~/.ssh/id_corp.pub)"
git config gpg.format ssh
git config commit.gpgsign true

Git passes this public key to ssh-keygen -Y sign, which asks whatever agent is on SSH_AUTH_SOCK for the matching private key.

Transport authentication (origin over SSH) #

git config core.sshCommand "ssh -i ~/.ssh/id_corp.pub -o IdentitiesOnly=yes"

If having issues, might want to specify the agent explicitly:

# 1Password
git config core.sshCommand 'ssh -i ~/.ssh/id_corp.pub -o IdentitiesOnly=yes -o IdentityAgent="~/Library/Group Containers/2BUA8C4S2C.com.1password/t/agent.sock"'

# Bitwarden
git config core.sshCommand "ssh -i ~/.ssh/id_corp.pub -o IdentitiesOnly=yes -o IdentityAgent=~/.bitwarden-ssh-agent.sock"

Verification #

GIT_SSH_COMMAND="$(git config core.sshCommand) -v" git fetch origin
git log --show-signature -1