The Living Thing / Notebooks :

Git tricks

Handy git commands

Remove a file from versioning without deleting:

git rm --cached blah.tmp

legit has simplified feature branch workflows.



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


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://
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-permissioned 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
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

jupyter diffing and merging is painful. Workaround: nbdime provides diffing and merging for notebooks. It has git integration:

nbdime config-git --enable --global

git-latexdiff, is the same for LaTeX.

Decent GUIs

See Git GUIs.