Basetta’s Website

Rants and Raves


First Post With Magneto

I have simply fallen in love with Magneto wrote by Don Melton.

The minimal approach of Magneto makes me to switch from Octopress.

Magneto is not “blog aware” like some other systems, but it allows you to write a site controller script and plugins which can easily generate blog posts, an index page and a RSS feed. This is how I use it. There may be more work up front compared to other tools, but Magneto gives you very precise control over its behavior and output.

For converting the Octopress posts to a Magneto compatible format I used the following script

The rendering using magneto is amazingly fast.

Protect Your Private Data Using Gitconfig Include Directive

I am using a dotfiles git repository in order to keep my machine preferences in sync.

This is working pretty well, until you realise that are some config entries that are clashing with each other.

One of those cases, is the common situation of having two github accounts – one for work and one for private purposes. In this case we would like to share the common git configuration but not the committer’s author name and email address held in the .gitconfig.

Recently, git added a new feature, the include directive for config files ( since 1.7.10 ) that can solve the problem. With the include feature you can split your gitconfig across multiple files, so you can have the common git configuration in one file, and private information in another.

Let’s have a look at an example :

  • Add the include directive to your .gitconfig ( this is the file in your git dotfiles repository )
[include]
path = ~/.gitconfig_user
  • Add to ~/.gitconfig_user your private data
[user]
name = Silvio Berlusconi
email = silvio.berlusconi@bungabunga.it
  • Test if the config is working properly
$ git config user.name
Silvio Berlusconi
$ git config user.email
silvio.berlusconi@bungabunga.it

Extract a Directory From a Git Branch/Repository Preserving The History

At work we wanted to extract from a branch a subdirectory containing a specific feature that had to be used from everyone in the team.

Just for sake of example, let’s define the terms of our problem. Our repository (MAIN) structure looks like:

MAIN/
        Library/
            libA/
            libB/
            libC/

Our goal is to extract the libA contained in the branch FTR-B in its own branch called FTR-A.

If you are not interested in preserving the history the task is quite easy. Git checkout is our friend in this case.

$ git checkout master
$ git checkout -b FTR-A
$ git checkout FTR-B Library/libA
$ git commit -a -m "Extract libA"
$ git push

More complicated is the case in which preserving the history is a matter of importance. For God’s sake git has a powerful command git filter-branch. The following are my notes and observations, for pleasing my poor memory.

  • Clone the local repository into a temporary repository DIRTY.
$ git clone ~/MAIN/ ~/DIRTY/
$ cd DIRTY
$ git checkout FTR-B
  • Remove everything except the desired subdirectory ( libA ).
$ git filter-branch --prune-empty --tree-filter 'rm -rf Library/libB Library/libC'

Basically, Git filter-branch executes a command on each commit in a specific branch. Instead of the option tree-filter you could have used subdirectory-filter that removes everything except the desired directory moving it up to the root project. I will explain it better in another post.

  • Clean all the cruft
$ git gc --aggressive
  • Merge the new feature in its own branch FTR-A.
$ cd ~/MAIN
$ git remote add dirty ~/DIRTY
$ git fetch dirty
$ git branch dirty remotes/tools/FTR-B
$ git checkout master
$ git checkout -b FTR-A
$ git merge dirty
$ git remote rm dirty
  • Create a pull request

How to fetch upstream changes in git easily

It is quite common to update your git fork repository with the upstream changes.

Here it is the workflow I use to keep synchronize my branch with Octopress.

  • First of all, we should configure the remotes.
$ git remote add upstream git://github.com/imathis/octopress.git
  • Check the remotes
$ git remote
  • Merge/Rebase the changes
$ git fetch origin -v
$ git fetch upstream -v
$ git merge upstream/master

If you prefere you can create an alias in your .gitconfig.

[alias]
  pull_upstream = !"git fetch origin -v; git fetch upstream -v; git merge upstream/master"

Now git pull_upstream will fetch the changes of both remotes, and the merge in the upstream changes.

Back Online

It has been nearly four years since I last posted. Quite a lot. Anyhow, now I am back online thanks to Octopress and Github pages.

I’ll have more to do:

  • write a catch up post
  • importing the old posts parked here after my previous Django blog abandoned me.
  • personalized the Octopress default template.