Who's using git? I've got questions

Ye' old general discussion board. Basically, for everything that isn't covered elsewhere. Come here to shoot the breeze, shoot your mouth off, or whatever suits your fancy.
This forum is not for asking programming related questions.

Moderator: General Moderators

Post Reply
User avatar
flying_circus
Forum Regular
Posts: 732
Joined: Wed Mar 05, 2008 10:23 pm
Location: Sunriver, OR

Who's using git? I've got questions

Post by flying_circus »

Finally rebuilt my dev server at home and am forcing myself to use a vcs. I've settled on git, but am having trouble figuring out the best implementation and am looking for feedback. It is possible I am missing something fundamental, so all suggestions are welcome :)

1) I understand that each "project" should have it's own repository. Since I develop on my desktop or laptop and commit to the server, the server should always have a reasonably current copy of my work. Lets say I reformat my desktop (windows machine) and now I want to pull down a copy of a few of the projects I am working on. How do I fetch a list of repositories on the server? Is this possible? Otherwise I have to know the name of the repositories explicitly, correct?

I am accessing with ssh - git@devbox:repo_name


2) What kind of a directory structure are you using? Hopefully this ascii art turns out, but is this similar to what you have set up or is there a better way?

[text]/raid_01
|
- mysql/*
- git/repositories/*
- www/html/
|
- git/* (exported by post-recieve hooks)
- * ad-hoc projects[/text]


When I commit to a git repo, I am using post-receive hooks to populate a directory in the wwwroot/git directory with a snapshot of the project, basically as would be uploaded to the client server. This keeps internal files (like .psd artwork files) seperate from external files

This allows me to browse project websites using something like

http://devbox/git/project_a
http://devbox/git/project_b
http://devbox/git/project_c

and still have the freedom to do ad-hoc coding anywhere outside of the git web directory.

http://devbox/ad-hoc/dev_network_challenges.php
http://devbox/test/array_functions.php
http://devbox/security/auth_test.php
etc...
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: Who's using git? I've got questions

Post by Chris Corbyn »

Git is a fine choice for a VCS. Many say that Mercurial is good too, though I have not used it myself.
1) I understand that each "project" should have it's own repository. Since I develop on my desktop or laptop and commit to the server, the server should always have a reasonably current copy of my work. Lets say I reformat my desktop (windows machine) and now I want to pull down a copy of a few of the projects I am working on. How do I fetch a list of repositories on the server? Is this possible? Otherwise I have to know the name of the repositories explicitly, correct?
First things first, some terminology. You don't "commit" to the server, like you do with, say, subversion. You commit to your local repository and then (at some point) you "push" to the server. Effectively there are two copies of the repository: one on the server, and one locally. The one on the server is not necessary, however; most of git's core features all work locally. Pushing and pulling is a pretty small aspect of git.

Now to answer your question, the "server" is just a machine that has git installed. Git doesn't manage multiple projects. Each project is a separate git repository. If you need a list of all the repositories on a server, you'll have to put them all in a known-location and then just `ls' the directory for sub-directories.

`ssh git@devbox ls *.git' will do that, if you're using SSH and all the repositories are in your home directory (provided they are "bare" repositories... which means there is no working tree on the server, only the .git directory).
2) What kind of a directory structure are you using?
I'm unclear what you mean here. You'll probably have to clarify.

Inside the repository, the working tree directory structure is irrelevant to git. Just use whatever you would normally use, if you weren't using git.

If you're talking about sysadmin type stuff, regarding where git repositories are located on a server, I don't do this. I use github and pay for private repositories where the project is of commercial interest (the prices are reasonable). In terms of "deploying" to production, we do in fact have copies of our git repositories on the production servers, which means our deployment process is just a case of initiating a pull (a fast-forward in reality) on the server, in order to get the files up-to-date, then running some post-installation scripts. We deploy from ruby these days, so that is done via Capistrano, which just SSH's into the server and executes the relevant shell commands. We also have some projects set up to deploy as soon as all of our unit tests on the master branch pass (initiated via a post-receive hook on github, executed on a Jenkins server).
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: Who's using git? I've got questions

Post by Chris Corbyn »

It's pretty serious reading, but I heartily recommend reading Git From the Bottom Up: http://ftp.newartisans.com/pub/git.from.bottom.up.pdf, which makes you realize how wonderfully simple git is, by understanding how it works internally.
User avatar
flying_circus
Forum Regular
Posts: 732
Joined: Wed Mar 05, 2008 10:23 pm
Location: Sunriver, OR

Re: Who's using git? I've got questions

Post by flying_circus »

Wow Chris, thanks! I think you answered my questions either directly or indirectly. It's true, this is my first venture with a vcs in general and being a 1-man show, I dont have an example (at work) to follow. I am making it up as I go based on my (mis)understanding of it :)

I dont run a webserver on my development machine, traditionally I've kept all of my project files on devbox, and access them over the network via samba. Devbox is also a webserver, so as soon as I save the file on devbox, I could refresh my client browser to see the changes. I'm beginning to realize that may not be the best method with git.

I am trying to push everything to the server where git is installed, have git process post-receive hooks to export a "build" of the site to devbox's www root, and utilize devboxs web server to view it. It sounds like my workflow isnt the greatest match, especially in a multi-developer environment. I will have to think on this more.

Thanks for your feedback and pointing me to the book. I've been slowly reading "Pro Git" as well.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: Who's using git? I've got questions

Post by Chris Corbyn »

Not running a web server "locally" isn't actually that bad. I don't run a web server on my host machine (OS X). I have a Virtual Machine set up that runs linux, as close to the same configuration as in production as is reasonably possible. If you're on a UNIX-like system, you can work on a sshfs mount (via fuse/macfuse) to the VM, or via Samba (as you do), or if you want to get hard-core, learn Emacs or Vim and develop inside a terminal window direct on the VM. I personally prefer Vim, after a good stretch with Emacs, which is also a fine editor. There is a learning curve to using these tools, however, so a shared drive is perhaps the most feasible solution to start with.

Good luck!
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: Who's using git? I've got questions

Post by Jonah Bron »

Excellent advice Chris.

@flying_circus, my method is very similar to Chris's, except I usually do what you're doing on the server instead of using a private GitHub repository. I create a "git" user, dedicated to managing any Git repositories. In all, I have three clones of the repository: one on my development machine, one in the git user (a bare repository, as there's no need for a working tree), one in the web server directory. The local and production repositories have the "git" repository configured as the "origin". After I make a commit to the repository on my computer, I push to the "git" user. After that, I SSH into the server and pull from the "git" repo to the production server. I keep another branch separate from master for the production server, to keep things neat.

As for the organising of the repos on the "git" user, I just name the Git dir to projectname.git, and access it as git@server:projectname.git.

Edit: I should point out that the git repository actually contains the web server directory. This keeps the .git directory above the web root. The alternative is to block access to it with .htaccess, though this is more risky (susceptible to human error), and it doesn't allow you to keep other files under VC.
User avatar
flying_circus
Forum Regular
Posts: 732
Joined: Wed Mar 05, 2008 10:23 pm
Location: Sunriver, OR

Re: Who's using git? I've got questions

Post by flying_circus »

Thanks again guys :)

I finally got some time to play with it and spent somewhere between 15-20 hours figuring it all out. I hate it when linux repos have different versions of software and name them like "gitolite" and "gitolite3" (grrr!). I ended up with a setup using gitolite(3) and gitweb. I created a few virtual hosts and everything seems to be working. I couldnt figure out how to clone repos using ssh and certificates so I'm using smartgit as a client (cross platform).

I'm not sure if I will stick with this exact setup, but I will try and force myself to use it for a month or two and atleast gain a minimal skillset and knowlegde of git in general. I also found an article online and am going to try and use it's branching model, so we'll see how it goes:
http://nvie.com/posts/a-successful-git-branching-model/

Only thing left to figure out is how exactly sparse checkouts work and how I can automate it in the post-receive hook.

Cya!
Post Reply