Handy git commands
Remove a file from versioning without deleting:
legit has simplified feature branch workflows.
See the fastai masterclass for many more handy helpful tips/links/scripts/recommendations.
The simpleest way of integrating external porjects is as subtrees. Once this is set up you can mostly ignore them.
Con: Rebasin’ despite ’em is slow and involved.
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.
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
I think bfg also does this. There is also native support for that:
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
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:
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.