July 30, 2014
Hot Topics:
RSS RSS feed Download our iPhone app

Using Git Version Control for Writing Projects, Page 2

6. Ignoring Project Notes

When working on writing projects I'll often maintain various files, which contain research notes that are really only useful during the course of the project. Because I'm not interested in maintaining these files within the repository, I'll use Git's .gitignore file to prevent them from being included. For instance, I'll use the file extension .notes for these files, and prevent them from being tracked by adding the following line to .gitignore:

*.notes

7. Searching the Commit Log

Writing large documents such as books is very much a marathon, with the finish line being the culmination of thousands of smaller victories. I tend to measure productivity in terms of my chapter-specific milestones, and so when committing changes will prefix the commit message using a string, which looks like CHAPTER04. I can then use Git's log search capabilities to review the timeline of changes for that chapter:

$ git log --grep="CHAPTER04"

8. Backing Up Your Work with GitHub

There are few situations more sickening than realizing your laptop hard drive has decided to retire early, taking with it several projects that haven't been backed up since you last pulled out the USB key a few weeks prior. Save yourself the hassle and back up your Git repositories using an online service such as GitHub. For just a few dollars per month, you can maintain several repositories that allow you to easily backup your projects with just a few keystrokes. For instance, after configuring a new GitHub-hosted project, my daily workflow looks like this:

write some material…
$ git status
...
$ git add .
...
$ git commit -m "Added new section on the XYZ API"
...
$ git push origin master

That last command results in all of the changes made since my last "backup" being sent to my project's GitHub repository, eliminating the need for manual backups with a USB drive or similar media.

9. Building Books with Postcommit

Using hooks it's possible to automate the execution of tasks in accordance with significant repository-related events, such as following commit. These hooks are stored in your project's .git/hooks directory, and can be written in any language supported by your operating system, for instance bash, Ruby or Python. For instance, because I like to produce PDF-based snapshots of books, which can be passed around to reviewers, my post-commit hook is a shell script that converts book chapters (written in Docbook format) into PDFs using an XSL-style sheet.

While this conversion process is out of the scope of this article, you can nonetheless experiment with post-commit hooks by renaming the file post-commit.sample to post-commit (again, found in your project's .git/hooks directory), and then modifying the file to look like this:

#!/bin/bash

echo "post-commit task executed!"

Of course, this assumes you're running an operating system which supports the Bash shell. The next time you initiate a commit, this statement will be output to the screen!

10. Coloring Your Commits with Flashbake

The flashbake project is a really interesting Git-oriented project that supports a series of plugins capable of incorporating information from the outside world into your commit messages. For instance, flashbake can retrieve a list of recently posted Twitter updates, your current geographical coordinates, and current weather conditions, adding all of this information to your commit message. This certainly has the potential of providing readers with not only additional insights into the author's writing environment, but actually tying the changing environment to specific parts of a writer's work.

About the Author

Jason Gilmore is founder of WJGilmore.com. He also is the author of several popular books, including "Easy PHP Websites with the Zend Framework", "Easy PayPal with PHP", and "Beginning PHP and MySQL, Third Edition".



Originally published on http://www.developer.com.

Page 2 of 2



Comment and Contribute

 


(Maximum characters: 1200). You have characters left.

 

 


Sitemap | Contact Us

Rocket Fuel