How to log IPython history to text file?

You can also choose which lines you would like to save. E.g.

%history 1 7-8 10 -f /tmp/bar.py

This will save line 1, 7 to 8 and 10 to a temp file bar.py. If you need the whole just skip the part of the line.

%history -f /tmp/foo.py

You can export all of your history in IPython to a text file with the %history magic like this:

%history -g -f filename

One way of getting what you want might be to do that export in a git hook. I usually put these "sync an external resource" actions in the post-checkout git hook.