I use git enough now that my repositories are getting a bit messy. I decided to centralize them all in one place so I can access them over the network. (You know, the distributed part of DVCS). There’s lots of options, I settled on just using a bunch of bare repositories on a host I can ssh to.
Alternatives I considered.. Dropbox is a good alternative for the central git repository but I’ve got my own server so I’m using that. The git:// protocol seems like unnecessary complication. As for hosting and web frontends.. GitHub is too expensive for my 10+ private repos,, charging per repo. Sites like repositoryhosting, gitorious, codeplane, and bitbucket have cheap or free options, but I don’t really need a centralized host since I’m mostly working alone. I could also have gotten fancy and installed something like gitolite to have a webapp front end, but that’s overkill for me now. Maybe I’ll set up gitweb at some point.
Here’s how I migrated my exisiting ad-hoc repos to one canonical gitrepos directory on a server. I found a lot of conflicting and incomplete info on how to do this, for instance these notes, this blog post, and this stackoverflow post. Correctly getting all branches into the new canonical repo and then patching up the config of the old ad-hoc repo is not straightforward. I’m not confident this is really correct, either, but it seems to work for simple things.
Find all the .git repos. Still have to hand-edit this list. $ find ~ -type d -name .git | egrep -v '/d3|polymaps/' Create a new bare repo in my new ~/gitrepos directory, based on code from ~/src/dotfiles. $ cd ~/gitrepos $ git clone --bare ~/src/dotfiles dotfiles $ # is this a good idea? necessary? $ # cd dotfiles; git remote rm origin Change my old ad-hoc repo to consider this bare repo as its origin. $ git remote add origin ~/gitrepos/dotfiles $ git push $ git branch --set-upstream master origin/master
That bit about pushing and then setting the upstream is 100% black magic for me, I have no idea what it does. It seems to be necessary to create the magic so that later “git status” will tell you if your local branch is ahead of the canonical copy in ~/gitrepos. The push is necessary for some git config reason, even though there’s nothing to push. I find it confusing how git uses branches to track remote repos.
Also useful: “git remote -v” for seeing what remotes are configured, and “git branch -avv” for seeing more about git’s local view of various branches and remotes.
None of those examples above use a really remote repository, it’s all just Unix file paths. You can so name repositories like “email@example.com:~/gitrepos/dotfiles” and it will ssh to example.com and everything just works.