Skip to content

Git

Source control.

Conventions

Development Workflow

How to

Core Git

Extras

Untracked files

List untracked files and dirs:

git clean -fdn

List modification times:

git clean -n | awk '{print $3}' | xargs -I {} stat -c '%y %n' {} | sort -n

Remove untracked files and dirs:

git clean -fd

Stash untracked files

git stash --include-untracked # short arg is -u

Deal with Obsidian sync pulling changes (when you didn't make local changes)

git fetch --all
git reset --hard origin/master

Share via sneakernet

wget https://github.com/mbailey.gpg
gpg --import ./mbailey.gpg
# cd cloned git repo
git bundle create mbailey.bundle --all
gpg --recipient mike@example.com  -e  mbailey.bundle
# Send me mbailey.bundle.gpg

Check out file from specific commit

git checkout c5f567 -- file1/to/restore file2/to/restore

Checkout Remote Branch

git fetch --all
git switch origin/gh-pages # creates branch if missing and sets up tracking for git pull/push

Diff two arbitrary files using git diff (e.g. for gpg files)

git diff --no-index file1 file2

Change commit author

git commit --amend --author="Alex Doe <alex@work.com>" --no-edit

For the last N commits:

git rebase -i HEAD~N -x "git commit --amend --author 'Author Name <author.name@mail.example>' --no-edit"

Update forked github repo

git remote add upstream git@github.com:original-repo/goes-here.git
git fetch upstream
git checkout master
git rebase upstream/master
git push origin master --force-with-lease

gpg diff

https://gist.github.com/marceloalmeida/e6593b93b388cdf1dbc282dffd424d1b#file-readme-md

git config --global diff.gpg.textconv "gpg --no-tty --decrypt"

echo "*.gpg filter=gpg diff=gpg" >> .gitattributes
echo "*.asc filter=gpg diff=gpg" >> .gitattributes

Delete dangling commits

shallow clone

Less files and no .git dir:

git clone --depth=1 git://someserver/somerepo dirformynewrepo
rm -rf !$/.git

See also