WebFaction
Community site: login faq

I'm hosting a Django application at: webapps/django_apps/apple.git.

I have created a directory from that location using:

git init --bare

Then I go to my local machine and run:

git clone name@name.webfactional.com:webapps/django_apps/apple.git

Then I create a file (locally) name test.txt, git add it, git commit, and then git push.

git push

goes through fine, but when I check the server the file isn't actually up there.

Am I doing something wrong?

Thanks!

asked 10 Jul '12, 13:43

sdasdas
111
accept rate: 0%

As an extra note, when I do: git log on the server I can see the commit history from my local machine. But the file doesn't appear in the directory...

(10 Jul '12, 14:55) sdasdas

I am running into this problem as well. What changes need to be made, so that pushing to the repo on my Webfaction account also pushes the files themselves?

(15 Nov '13, 00:38) Jonathan Head

The entire approach that this question suggests, as well as the question itself, is misguided. Pushing directly to the live repository will never by default have the effect of updating the working tree on the server, and there are very good reasons for this design.

If your goal is to have a Django application managed by a git repository, this is the way to do it.

If you want to manage a static application (such as PHP), this is the way to do it.

Hope that helps!

(15 Nov '13, 01:26) ryans ♦♦

I appreciate your answer, Ryan, and the in-depth guide you've created for managing static applications. That approach, however, is serious overkill for my particular needs.

I have a local repo, and need to push to a Webfaction repo located in a static PHP app, and have all the local files reflected in the Webfaction repo (which is also the root directory for that static PHP app).

I do understand that this may not be "desirable", but it is the workflow I have to setup. Is this possible, and if so, how might it be done?

(15 Nov '13, 02:20) Jonathan Head

A less robust but simpler approach might be possible. Have you considered:

  1. Make your application into a non-bare git repo
  2. Pushing to the repo
  3. Making a post-receive hook to "git checkout -f" and "git reset --hard"
  4. Using a .htaccess rule to hide the ".git" directory in the webroot
(15 Nov '13, 02:29) ryans ♦♦

Thanks for the suggestion - I'll give this a try and follow up afterwards. Appreciate it!

(15 Nov '13, 08:49) Jonathan Head

A quick update - this works great, and is just the setup I need.

The only difficulty I've had is setting up the post receive hook - I renamed the post-receive.sample file to just post-receive, as indicated in that file's comments, but the actual commands are not being implemented. Do I need to add a files match handler in the htaccess file to make sure it's treated as a cgi-script?

(16 Nov '13, 11:22) Jonathan Head

@Jonathan: Can you please confirm that your script has executable permissions?

(16 Nov '13, 17:34) waynek

@waynek - It did not have executable permissions (thanks!) - however, even after updating permissions on the script file, the git commands in post-receive are not getting triggered.

(16 Nov '13, 23:02) Jonathan Head

@Jonathan: At this point I think the best thing would be to log a support ticket with us from your WebFaction control panel so that we can take a closer look. Thank you.

(16 Nov '13, 23:15) waynek

Roger that, thanks Wayne.

(17 Nov '13, 04:20) Jonathan Head

For those who are looking to do something like this, I had to add cd .. and GIT_DIR='.git' before the git reset command in the post-receive script in order to get this to work.

(17 Nov '13, 07:59) Jonathan Head
showing 5 of 12 show 7 more comments

A "bare" repository does not contain files the way a regular repository does. Well, technically speaking it does. What you view when you clone a repository is actually working directory, not the repository itself (that's the .git directory). A bare repository is just the repository, not the working directory.

If you need to view files stored in a repository, you'll need to clone the repository somewhere (or set it up without the --bare option, but I wouldn't recommend that).

permanent link

answered 11 Jul '12, 05:45

David L ♦♦
1.4k13
accept rate: 45%

I ran into this same problem and found a nice solution. I am going to explain it in very simple terms because some of these steps eluded me when I was first figuring this out, so I hope this helps anyone who is interested.

I put all my webfaction git repos in ~/git. First make a git folder:

mkdir ~/git

Then initialize a bare repo in a new subfolder:

mkdir ~/git/myapp.git
cd ~/git/myapp.git
git init --bare

Now setup a post-receive hook:

cd hooks
touch post-receive
vi post-receive

Now you need to write this file in vi, first press i to enter insert mode then type the following:

#!/bin/sh
GIT_WORK_TREE=/home/username/webapps/myapp git checkout -f

Press esc to exit insert mode, then :, then x, then press enter to save and exit. Now your git repo is conveniently outside of your webapps/myapp folder, so no need for an .htaccess solution. Also, the working tree is pointing at your web facing folder, so those files get updated when you do a git push. One more thing to make it work:

chmod +x post-receive

Switch back to your local machine/repo that you'll be pushing from and add a new remote repo (I am calling it 'dev'):

git remote add dev username@username.webfactional.com:git/myapp.git

Then you can just:

git add .
git commit -m "this push is getting hooked"
git push dev

And of course, substitute "username" for your actual username. I learned most of this here.

permanent link

answered 18 Nov '13, 03:40

jrode
1
accept rate: 0%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×909
×111

question asked: 10 Jul '12, 13:43

question was seen: 3,136 times

last updated: 18 Nov '13, 03:40

WEBFACTION
REACH US
SUPPORT
AFFILIATE PROGRAM
LEGAL
© COPYRIGHT 2003-2019 SWARMA LIMITED - WEBFACTION IS A SERVICE OF SWARMA LIMITED
REGISTERED IN ENGLAND AND WALES 5729350 - VAT REGISTRATION NUMBER 877397162
5TH FLOOR, THE OLD VINYL FACTORY, HAYES, UB3 1HA, UNITED KINGDOM