Community site: login faq

I've tried now for several hours understanding how to use Git with webfaction. And even with the documentation I cannot get it to work.

I have a Django app at: webapps/django_app/project_name/

I have a Git repo at: webapps/git_app/repos/my_repo.git

I assume the following workflow:

  1. Make som local changes
  2. Push it to git_app
  3. Clone/pull to django _app from git _app.

Is this correct ? (New to git)


  1. How do i copy the django_app content over to my local repo?
  2. How do I push my local changes over to git_app
  3. How do I get the git _app files over to django _app?

Some really newbie questions there, but hope to get some help!

asked 28 Dec '10, 19:10

accept rate: 0%

For updating your Django (or any) application directly when you push to your git repository, I prefer the method described at:


In a nutshell, you would create a post-receive hook that looks something like:

GIT_WORK_TREE=/home/username/webapps/django/myproject git checkout -f master
GIT_WORK_TREE=/home/username/webapps/django/myproject git reset --hard

Replacing "username" with your username, "django" with your django web application's name, and "myproject" with the django project name.

You would specifically be committing the django project to git ("myproject" in this example), and not the entire /home/username/webapps/django application directory (which includes extra things such as the private apache server which runs your application).

The post-receive hook to update would be the file at:


where "username" is your username, "git" is your git application's name, and "djangorepo.git" is the name of the git repository you're using for your django project directory.

You will also need to ensure that the hook is executable:

chmod +x /home/username/webapps/git/repos/djangorepo.git/hooks/post-receive

Hope that helps!

permanent link

answered 28 Jan '11, 22:15

accept rate: 43%

edited 29 Aug '13, 05:39

Another point of interest: You can "template-ify" your settings file. So, for example, if you have this running locally (with a different settings file), just make something like "settings_template.py" which is added to your git repository, and then add "settings.py" into your .gitignore file (and don't add "settings.py" to the repository).

Now, you can instantly share the same django project between your local and remote systems without worrying about blowing away each side's respective settings files, and at the same time still be able to use the automatic update-on-push post-receive hook.

(14 Apr '11, 20:25) ryans

I know I am way late on this, but this topic interests me. However, I am a little confused by what you mean when you say "template-ify". What exactly would be using the settings_template.py?

(09 Oct '11, 01:08) miningold

Nothing would be using settings_template.py directly. However, let's pretend you and I are both collaborating on a Django project, which we want hosted on WebFaction but we also have our own private stacks on our respective local machines for development. We also have our own private PostgreSQL instances running.

The settings.py file is in charge of determining the configuration for that stack and database, and the necessary settings.py file for you, me, and for the WebFaction deployment will all be different.

Now, imagine that we just add settings.py to the git repository. If I set my own database "my_staging_database" with associated password under the DATABASES section in settings.py, and then push my changes to the repository, immediately I break both your deployment and the Webfaction deployment. The remote settings.py changes, and now the remote Django application attempts to use my local credentials to connect to the WebFaction PostgreSQL server, referencing a database that does not exist. The site goes down.

So, instead, we add settings_template.py to the repository to have a good starting point, and then copy that file to a local settings.py on each machine. We then set up the configuration for each machine and tell git to ignore the settings.py file. This way, we can push and pull without ruining each others' (and the webserver's) deploy settings. Hope that clarifies!


I now have changed my workflow a bit and find that the following works a bit better. I leave 'settings.py' as a versioned file, and create another called 'settings_local.py', which is inside of .gitignore. Then, the template is 'settings_local_template.py'. At the end of 'settings.py', add something like:

    from settings_local import *
except ImportError:

Then, define the deployment-specific options in 'settings_local.py', such as DATABASES, STATIC_URL, STATIC_ROOT, TEMPLATE_DIRS, STATICFILES_DIRS, etc.

This allows actual configuration options (like INSTALLED_APPS and MIDDLEWARE_CLASSES) to remain versioned.

(09 Oct '11, 01:29) ryans

Why do you add GIT_WORK_TREE=/home/username/webapps/django/myproject git reset --hard? It's not mentioned in the page you linked to.

(13 May '12, 20:35) Rupe

I have added this so that if you delete a file in the origin git repository, it is likewise deleted in the application directory on the webfaction server. I remember that originally I had encountered an issue where under certain circumstances extra files would be left around, and performing the git reset --hard more strongly ensures that the server-side application stays in sync with the local development application. This also helps to ensure that you could also add an apache restart command to the post-receive hook without having strange inconsistencies.

(13 May '12, 20:44) ryans

If you're prompted for a password when pushing or pulling over SSH, you can fix that by setting up a SSH keypair to use for authentication. The steps are almost identical to those in our SSH key documentation but with one difference: both steps should be run while logged into SSH on your WebFaction server.

(06 Feb '13, 10:23) seanf
showing 5 of 6 show 1 more comments

Our official documentation on GIT is here,


You should be able to simply push and pull your code using SSH. This section specifically should answer your questions with examples,

permanent link

answered 28 Dec '10, 20:10

accept rate: 23%

The foloowing link is DEAD. - [http://docs.webfaction.com/software/git.html#pushing-and-pulling-with-a-repository]

It only goes to [http://docs.webfaction.com/software/git.htm]

All this Git stuff needs A LOT of attention.

(11 Feb '19, 21:31) jdor2

How do you include the static files in the Git repo, while having a separatie static files app? What I mean is, in my local environment I have the static files folder in my project folder like:


But on Webfaction the static folder is a separate app so nginx handles the static files. But then we have the problem that with ryans solution that an automatic gitcheckout won't work (it works, but it will create a static/ folder in your myproject app and that's not what we want). I've tried to create a symbolic link in the myproject folder named static/, which points to the static app. But, when git checkouts to the working tree, it overwrites the symbolic link with the actual static folder.

Any ideas?

permanent link

answered 23 Oct '12, 15:54

accept rate: 0%

edited 23 Oct '12, 15:56

Just add commands to the post-commit script to copy the static files to wherever they need to be, eg:

GIT_WORK_TREE=/home/username/webapps/django/myproject git checkout -f
GIT_WORK_TREE=/home/username/webapps/django/myproject git reset --hard
rm -rf /home/username/webapps/my_static_app/*
cp -r /home/username/webapps/django/myproject/static/* /home/username/webapps/my_static_app/

Or, replace your static-only app with a static-only symlink app pointing to /home/username/webapps/django/myproject/static/ (ie, make your symlink app point to the real directory within your project directory, instead of having the symlink itself in the project directory pointing to a directory outside of it.).

(23 Oct '12, 16:00) seanf

Thank you seanf, I've tried the second solution and that works great. I didn't know that it was possible to serve 2 different folders in 1 app with 2 different http servers (apache/mod_wsgi for the django files, nginx for the static files).

(23 Oct '12, 16:28) Peter
Your answer
toggle preview

Follow this question

By Email:

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



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:


question asked: 28 Dec '10, 19:10

question was seen: 23,175 times

last updated: 11 Feb '19, 21:31