I just finished working my way through a chapter of a new iPhone dev book. I had a working copy of the example of the book and felt like mucking around with it to learn more on my own. I still want to keep the original state of the code, but I am too lazy to setup a repository for such “disposable” code.
Years of using Subversion have made me lazy like that. I am *really* lazy. I always forget what the steps are to create a repo, mostly because it is usually such an infrequent task for me. But now that Git makes it so easy to create a repo right there in the project directory I’m working on without littering the whole thing with junk… hmmm… Maybe I should be using it even for “disposable” code.
So to facilitate this new behavior I wrote a little script. It expects the root of the project to be the current working directory, so make sure you “cd” into the right place before invoking it. Here is what it does:
- Creates a new new git repository at the CWD
- Creates a new .gitignore file to ignore:
- the build directory
- user.pbxuser file inside the project
- user.perspectivev3 file inside the project
- Adds all the files in the CWD to the index, staging them for inclusion in the next commit
- finally commit everything with the default message “- initial commit to Repository”
I think this will be useful to me, and so I post it here in case it is useful to others. It is really very simple. Please let me know if you have any suggestions to improve it.
#!/bin/bash
git init
cat > .gitignore <<EOF
build
*.xcodeproj/*.pbxuser
*.xcodeproj/*.perspectivev3
EOF
git add .
git commit -a -m "- initial commit to Repository"

