Git and Python

Ryan Dwyer, 2014-12-17

Check installation

In [1]:
! git --version
! pip --version
! python --version
git version 2.1.3
pip 1.5.6 from /Users/ryandwyer/anaconda/lib/python2.7/site-packages (python 2.7)
Python 2.7.8 :: Anaconda 2.0.1 (x86_64)

Newtex python helper

Install using,

git clone https://github.com/ryanpdwyer/newtex.git
cd newtex
python setup.py develop

or in SourceTree,

File > New / Clone

Type the url https://github.com/ryanpdwyer/newtex.git, and edit the path where the folder will be created if you want, and click Clone. Double-click the repository in bookmarks, and then click the Terminal icon in the corner of the window.

In []:
# ! git clone https://github.com/ryanpdwyer/newtex.git
# %cd newtex
# ! python setup.py develop

Configuring Newtex helper

  • In a Terminal, Powershell, or GitBash window, run:
newtex
  • First, this should guide you through setting up a configuration file:
Setup config directory at ~/newtex_template? [y/N]:
  • It should open an editor to your config.yaml file.
  • Make sure to set
    • master_bib_file
    • authors
    • affiliations

Using Newtex helper

  • The helper will do the following things:
    • Create a new LaTeX document in a folder in the current directory
    • Make the initial git commit of the new document
    • Setup a bare repository on Dropbox, with git push and git pull configured.
    • Create a labeled figure directory on Dropbox for any very large or draft figures

Example

Execute:

cd ~/Dropbox [or where ever you would like your copy of the document to live]
newtex

You should see:

Short name for document (2-3 words)?:

Enter a short name—this will go in your document title and the folder title like this:

folder name: _JAM_{doc type}__{Last}{Year}{Month}__{short name}
document name:                {Last}{Year}{Month}__{short name}.tex

Example

You should see:

What is the document's title?:

After entering the full document title, you should see:

    FP: Flight Plan
    MS: Manuscript
    GT: Grant
    GR: Grant Report
    RP: Report

What type is the document? :

Enter one of the options, then you should see lots of output, as the files are copied, repository is created, commited, etc. Now you can work on your document!

Useful git featurs

  • git diff --color-words
    • See changes by words, rather than lines. Useful for LaTeX files

Bare repositories

If you already have a git repository set up in the directory /path/to/my_repository, you can implement this protocol with the following commands:

First, you should rename the folder my_repository to something like _JAM_FP__Last201412__my_repository.

From your Dropbox folder,

git clone --bare /path/to/_JAM_FP__Last201412__my_repository/.git/

Back in the folder /path/to/_JAM_FP__Last201412__my_repository, do,

git remote add origin ~/Dropbox/_JAM_FP__Last201412__my_repository.git
git push -u origin master

Now you should be able to push / pull.

Other useful tools

Mac

Windows

  • It's helpful to setup git so that you can use it from PowerShell.
  • When installing (or re-installing) git, select: