Git
Behind on coder chic
Git Down: A Recommendation of Swicegood's Pragmatic Version Control Using Git
Cleaning Up a Bloated Git Repository
I have been using a static site generator where the content is managed in git
version control for this site for a number of years.
A decision I punted on really understanding when I was trying to figure how to get the darned thing working was how to handle static assets (images, mostly). To “get it working” I decided to commit the assets to the repository.
Fast-forward to the present: I was unable to deploy my site because the image copying was exceeding the processing limits on my web server.
I needed to trim the footprint of my git repository. Ultimately I reduced the footprint by 100x. Here are the tools I used to handle the problem.
Working With Git Submodules in Hugo
Additional Updates: 2021-03-15
I’ve been really enjoying Hugo static-site generation. I’ve been customizing it as a book-writing framework, and it’s great!
That said, Hugo likes using git
submodules to manage themes and similar. As a
result of this, when you clone the “main” repo again, your submodules are bare.
One can change this behavior if one remembers, but I’m in such a rut of git clone <url>
that I don’t really think about getting my sub-modules until it’s
too late.
To clone and get submodules: git clone --recurse-submodules <url>
But if you forget…
git submodule update --init # foreach submodule listed in .gitmodules do...
--recursive # git update --init
To fetch latest:
$ cd submodule/path
$ git fetch
$ git reset --hard origin/master # or git checkout -q <origin/master SHA>
To add a new submodule:
$ git submodule add <remote_url> <destination_folder>
And to remove one:
$ git submodule deinit <submodule>
$ git rm <submodule>
References
- Stack Overflow
- I’ve also copied
gitaarik
’s awesome explanation (to save bit rot) after the jump.
Cleaning Up Your Github Repos
I was recently reduced from the staff of the Flatiron School and, after my GitHub accounts were terminated, I still had a ton of repos that had been forked from the company’s accounts to my own. The GitHub web UI doesn’t help with bulk actions, so I scripted it.
Strategy
- Use
hub
’s low-level API to generate a death list in a file - Peruse the file
- Feed the file into
hub
to do the deletion