The Living Thing / Notebooks :

Stupid git tricks

Contents

Decent GUIs

Git is remarkable for how smooth, fast, and tiny it is as a command-line application.

Because of some as-yet unarticulated conservation law, this means that all the GUIs for it are clunky, slow, and bloated. To go from the magically simple experience of git, to one with better visualisation, you must sacrifice time upon the altar of thread locks.

subtrees

creatin’:

git fetch remote branch
git subtree add --prefix=subdir remote branch --squash

updatin’:

git fetch remote branch
git subtree pull --prefix=subdir remote branch --squash
git subtree push --prefix=subdir remote branch --squash

Rebasin’ despite ‘em is slow and involved

importing some files across a branch

git checkout my_branch -- my_file/

Garbage collecting

In brief, this will purge a lot of stuff from a constipated repo in emergencies:

git reflog expire --expire=now --all && git gc --prune=now

In depth explanation.

Editing history

Cleaning out all big files

bfg does that:

git clone --mirror git://example.com/some-big-repo.git
java -jar bfg.jar --strip-blobs-bigger-than 10M some-big-repo.git
cd some-big-repo.git
git reflog expire --expire=now --all && git gc --prune=now --aggressive
git push

Deleting specific things

I think bfg also does this. There is also native support for that:

git filter-branch -f --index-filter 'git rm -r --cached --ignore-unmatch unwanted_files'open .

Making it work with a broken-permissions FS

e.g. you are editing a git repo on NTFS via Linux and things are silly.

git config core.filemode false

Splitting off a sub-project

Use subtree split to prise out one chunk. It has a few wrinkles but is fast and easy.

pushd superproject
git subtree split -P project_subdir -b project_branch
popd
mkdir project
pushd project
git init
git pull ../superproject project_branch

Alternatively, to comprehensively rewrite history to exclude everything outside a subdir:

pushd superproject
cd ..
git clone superproject subproject
pushd subproject
git filter-branch --subdirectory-filter project_subdir --prune-empty -- --all

content-specific diffing

Handy git commands

legit has simplifed feature branch workflows.