My own git reference. See also classic git tips.
See the fastai masterclass for many more handy helpful tips/links/scripts/recommendations.
Handy git commands
Remove a file from versioning without deleting:
legit has simplified feature branch workflows.
Filters: smudge and clean,
The simplest way of integrating external projects is as subtrees. Once this is set up you can mostly ignore them.
putting a substree into a project
Con: Rebasin’ despite ’em is slow and involved.
Splitting off a sub-project
subtree split to prise out one chunk. It has a few wrinkles but is fast and easy.
Alternatively, to comprehensively rewrite history to exclude everything outside a subdir:
Include external projects as separate repositories within you repository is also possible, but I won’t document it here, since it’s so tedious and has so many things that go wrong if you are not disciplined.
not repeating yourself during merges
git rerere automates this
git config --global rerere.enabled true git config --global rerere.autoupdate true
Importing some files across a branch
In brief, this will purge a lot of stuff from a constipated repo in emergencies:
Cleaning out all big files
bfg does that:
Deleting specific things
bfg also does this. There is also native support:
Making it work with a broken-permissioned FS
e.g. you are editing a git repo on NTFS via Linux and things are silly.
Detecting if there are changes to commit
if output=$(git status --porcelain) && [ -z "$output" ]; then # Working directory clean else # Uncommitted changes fi
Oh crap I’m leaving the office in a hurry and I just need to get my work into git ASAP for continuing on another computer. I don’t care about sensible commit messages because I am on my own private branch.
I put this little script in a file called
gitbang to automate the most common case.
#!/usr/bin/env bash if output=$(git status --porcelain) && [ -z "$output" ]; then echo "nothing to commit" else git add --all && git commit -m bang fi git pull && git push
jupyter diffing and merging is painful. Workaround: nbdime provides diffing and merging for notebooks. It has git integration:
git-latexdiff, is the same for LaTeX.
You can set up attributes so that these filters are invoked automatically. It’s a surprisingly under-documented thing for some reason.
See Git GUIs.
Which repo am I in?
For fish and bash shell, see bash-git-prompt.