Git Notes

Share a Repo between your Laptop and Another Computer

Create a bare git repository on the remote computer:

git init --bare

Push the commits on your local computer:

git push username@foo.cs.purdue.edu:/homes/username/Bare-Repo master -u

You can now clone that remote git repository on the remote computer and make any changes if needed.

Add a submodule

Add a submodule: Using Magit, I could just clone (or start) a new repository in a subdirectory and add the directory. It automatically added the required lines to .gitmodules and got things working.

Treat “binary” file as text

If your file is foo.exp, add in .gitattributes:

*.exp diff

Get commit count

git rev-list HEAD --count

# For a particular file

git rev-list HEAD --count -- one-button-change.md

Pre-commit hooks

Use (pre-commit)[http://pre-commit.com/].

To install:

sudo pip install pre-commit

Test on their demo repo.

To just run all the pre-commit hooks on all existing files:

pre-commit run --all-files

To install it as a Git hook:

pre-commit install

Note that the pre-commit hook checks only within the files you commit. For example, if I don’t commit any JS files, it won’t run the JS checks. That means that any already-committed non-compliant JS files will go undetected (unless you run the hooks on all files as mentioned before).

And, yes, it ignores unstaged files so that you don’t inadvertently test stuff that is not part of the commit.

To run it on some files (when debugging your failed commit, for instance):

pre-commit run --files main.py foo.py

Run all Tests before Commit

To run all tests in your repo before commit (using pre-commit), use the hook in my repository run-repo-tests.

Checkout Commit by Date

To checkout the commit you were at one year ago (helpful for nostalgic recollections and stats-gathering on New Year’s Eve):

git checkout `git rev-list -n 1 --before="1 year ago" master`

GitHub API

Get all data with authentication:

curl -u “username” https://api.github.com/repos/username

Created: December 13, 2017
Last modified: March 27, 2018
Status: in-progress notes
Tags: notes

comments powered by Disqus