Ryan Carmelo Briones

mostly harmless

Git branches for storing project assets April 03, 2008

Background: So I'm starting up a personal project. This is a the first of which I'm going to do completely on Git hosted at github. I'm really excited because I've been using git at work, and I have been watching github come to life on the sidelines. But all was not well in git-ville. In my projects, I tend to do a BUNCH of Photoshop mockups and slice them into HTML to "prototype" designs/layouts and I like to keep them in version control if possible. In Subversion, my repository would look something like this:


- _design
|- assets
|- mockups
- branches
- tags
|- myapp_0_1
|- myapp_0_2
- trunk
|- app
|- config
|- db
[Standard Rails Directories]



Unfortunately there's some problems with this kind of setup in Git. First, what we've come to know and love as trunk in Subversion, Git refers to, more or less, as the "master" branch. So there's no way to create some top-level directory above the root of my app to handle "odd" files.

Another option I thought of was just keeping a "design" folder in the root of my app, but REALLY didn't like that. Dirtay! The idea from the beginning is to keep these files separate from my actual app. And then when deploying I'd sure as heck want to make sure that I either 1) didn't get those files when pulling (which I'm pretty sure would be have been next to impossible) or 2) setup some sort of script to delete that crap out of my release directory as part of deploy process.

In the spirit of Git, why not create another branch to track the odd files? (git checkout -b designbranch) Is that one of the things that Git is supposed to be really good at? Yes, but part of the idea of branches is that they share a common history. git checkout -b designbranch is the same as git checkout -b designbranch HEAD or git checkout -b designbranch and that's not what I want, but it seems like the best plan with a little bit of deleting... and hacking... and ABSOLUTELY no merging.

My Solution: I decided tonight was the night. I needed to do something to get this done. I made a little mention of this at the office explaining to Jerry, who's going to help me out on the design stuff, what the plan was. Chad then interjected with the idea that Git was capable of making blank branches. Wow! That would be great. But a quick look at man git-branch left me wanting. There was nothing there that looked like you could create a blank branch.

Fast forward to "free time". So I'm ready to do this thing, and being the Git newb that I am, I wanted to make sure that I was creating this branch properly so that it would work with my github setup and subsequent clones would have access to the branch in the proper manner. I stop by one of my favorite git usage guides, and that pretty much had what I wanted, but it still didn't feel right, so I moved onward. After Googling at bit I found an article with a very interesting title: Creating a git branch without ancestry. Jackpot! This is exactly what I needed. And, after a few tests, rm projectdir; git clone git@...project.git and some success recreating this in /tmp here's what I came up with:



# standard github project setup
mkdir myproject
cd myproject
git init
touch README
git add README
git commit -m 'Intialize repo'
git remote add origin git@github.com:ryanbriones/myproject
git push origin

# add design branch
git symbolic-ref HEAD refs/heads/design
rm .git/index
mkdir assets mockups
echo 'Placeholder.' > assets/HOLDER
echo 'Placeholder.' > mockups/HOLDER
git add assets/ mockups/
git commit -m 'Initialize design branch'
git checkout -f master
git push origin design:refs/heads/design

# after making changes in design branch, push with
git push origin design



And so far I'm happy with this, but of course, if I run into any issues with this, I'll post something about it. Enjoy.