Categories
Computers Programming

Bare git

It’s been awhile since I’d learned anything interesting regarding git. Frankly, my needs are modest and I’ve been making due with my current work flow. My only real problem was every now and again, I’d run into trouble with merges.

Turns out, there was a perfectly reasonable explanation.

I didn’t know what the hell I was doing.

The light bulb started flickering when I started thinking it would be nice if I converted a source repository on my desktop to a repository that I didn’t work out of. My motivation was to ease synchronizing with the cloned repository on my laptop. Anytime I wanted to push changes from the laptop to the desktop, I had to make sure that the checked out branch on the desktop was different from branch I was pushing to.

The git-competent doubtless already recognize the errors of my ways.

I did a little research and got the sense that what I needed was a “bare” repository. I use the scare quotes here because I wasn’t entirely sure what a bare repo was. It just kept coming up in the examples I saw, without much in the way of explanation.

The light bulb was still flickering.

So first, I moved my source directory to another spot. Then, I created my bare repository like so:

git init --bare repo_dir

Then, I went to my relocated source directory, checked out the master branch and performed a push:

git push ~/path_to/repo_dir master

The command seemed to take. Emboldened, I also pushed the dev branch of my code. Then I went to the repo_dir and tried using the git branch command to see if the branches were in fact there, and also if any of the branches were checked out. You know, the ‘*’ character that marks the checked out branch? Well, it was there next to the master branch.

My first thought was “Drat, now I’ve just got another working repository. What the hell good was that ‘bare’ option?” So I attempted to checkout the dev branch- and it failed. So I tried checking out the master branch. It failed as well. Finally, I performed a simple ls command.

And finally, the light bulb turned on.

There were no source files. That’s what the ‘bare’ repository means- there’s no working tree. In fact, the contents of my new repository directory were basically that of the .git directory in my working repository. Now I had exactly what I wanted- a central spot that I could push my changes to without having to fiddle with branches. Essentially, working with it is just like working off a repository from gitorious or github now.

Now I also understood why I was always getting those merge warnings when pushing changes. It also explained why I kept coming across statements like “only push to a bare repository.”

I rounded out my modification by going to my source directory and using the remote command:

git remote add master ~/path_to/repo_dir

Now I was all set to push to the new repository.

I know this was a long winded explanation for something that wasn’t too complicated to begin with. Mainly, I wrote this up with the intention that someday, I might have a little chuckle at my own expense.

Leave a Reply

Your email address will not be published. Required fields are marked *