I am in the final phases of getting Git and Gitolite working. This is the current situation:
-
It's not really clear what servers you want to involve and how. I suppose the current workflow is somebody uploaded the files with no version control at all, right? But what is the new workflow supposed to be? Will they still work on the server, just use git to version them, will they work on them elsewhere and version them but then upload them as before, or do you want pushing to designated branch to check them out at the server? – Jan Hudec Aug 15 '11 at 12:34
-
1. There is indeed no current version control installed. So there are files already in production, but they are not version controlled. 2. The future should have all files on the server with git controlled. Every developer then pulls the copy from the server, works on it, and uploads it again through gitolite. – user852091 Aug 15 '11 at 12:46
2 Answers
The repositories under Gitolite management don't have working copies. So what you have to do is create another repositories with working copies, commit the data and push them to the gitolite-managed ones. The easiest thing is to do that on the server directly. Therefore under each of the www
directories, do:
cd /home/X/www
git init
git remote add origin /home/gitolite/repositories/X.git
git add .
git commit
git push origin
Now you have the data in the repositories, which was the easy part. I am assuming the same user account has access to both gitolite repositories and the server data (as you said in chat), which makes the issue significantly easier.
Now the repositories don't have alternates, so you have two copies of the data. To remove them, it's probably easiest to for each site do:
cd /home/X
git clone -s /home/gitolite/repositories/X.git www.new
mv www www.old
mv www.new www
rm -r www.old
(the -s
option to clone ensures the /home/X/www/.git
repository won't copy data from /home/gitolite/repositories/X.git
). And finally you have to install a hook. It's already explained in this question, but your situation is slightly easier. Since the data live on the same server and under the same user, you can simply install a post-update hook in all the gitolite repositories containing just:
#!/bin/sh
cd /home/X/www
git pull
If you ever want to move the repositories and web server to separate servers (which I'd recommend, because the web server, if it's facing out, should be in a "demilitarized zone", while the git server is better off in your internal network behind another line of firewalls), you will of course need the ssh trigger thing described in that other question.
-
Thanks a million for your effort Jan! Will try this out. Let me know if you know of any recommended reading for the local gitolite setup. – user852091 Aug 15 '11 at 13:23
I'm kind of understanding what you're saying, so please leave a comment if I'm off base, but you'll need to git clone
the empty repos you created over to your machine, then you can copy the .git
directory into your working directory. This should preserve the remotes.
The process should go something like:
git clone gitolite:a.git
# Message about copying an empty repo
cp -R a/.git/ /your/home/directory/a
After you've copied it, you should setup .gitignore
if necessary and add/commit it, then do a git add .
and something like git commit -m "initial commit"
then git push origin master
and it will populate the empty repo.

- 13,287
- 7
- 40
- 42
-
Thanks, but one important detail is different from my situation: the actual projects are on the server, not on the client. So should I just copy the created .git directories to the `/home/X/www/` folders? – user852091 Aug 15 '11 at 03:57
-
On your web server right? That is, _not_ on the gitolite server? In that case, yes, you can just copy the git folder over or run the above commands there. That's how I've got my webservers setup :) – Nic Aug 15 '11 at 04:17
-
Both the empty git repos and the actual files are on the _same_ server. They are only in different folders. The actual empty repos are in `/home/gitolite/repositories/`, whereas I have the files in `/home/a/www`. So the question is how to I move them from A to B? I tried just to copy them, but it says "The operation must be run in a work tree" – user852091 Aug 15 '11 at 11:16
-
@user852091: *Forget* that they are on the same server. All the operations must be done as if they were not, except you can use path instead of URLs. – Jan Hudec Aug 15 '11 at 11:56
-
@Jan Hudec: thanks, but I am still unable to do so. I cloned it from the /www/ directory, then copied the directory, and ran `git add .`. Still gives me `Operation must be run in a work tree`. Is there any documentation that explains how to create repos from existing files on the production server? I've been going over this for hours, can't get to understand it... – user852091 Aug 15 '11 at 12:00
-
It's not necessary to clone. They are empty and every empty repository is effectively the same. So you can just `git init` in the `/home/X/www` directories, `git remote add
` and you've got to the same place as by copying the checkouts. – Jan Hudec Aug 15 '11 at 12:01 -
@user852091: Don't bother copying. It's nonsense. Just `git init` and `git remote add origin gitolite:a.git`. – Jan Hudec Aug 15 '11 at 12:07
-
@Jan Hudec: from where do I `git remote add`? From the production server, right, being located in the `/home/`? I tried this but when I tried to clone them on the local machine, it does not work. It clones the empty repo located in /home/gitolite/repositories. And if I try to clone it directly: `clone gitolite:/home/a/www/`, then it says `/home/a/www/ ends with a slash; I don't like that` – user852091 Aug 15 '11 at 12:20
-
@user852091 let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/2491/discussion-between-jan-hudec-and-user852091) – Jan Hudec Aug 15 '11 at 12:26
-
@Jan Hudec thanks for the audit on the `remote add` - for some reason I thought it was much more involved than that (hence the clone suggestion) – Nic Aug 15 '11 at 14:29