My Git workflow for Webfaction, Bitbucket and local development in Django
I’ve posted this mostly for a reminder for myself, but others may find it helpful.
I currently develop any websites ideas I have in Django and host them on Webfaction (which I really like). To my everlasting shame as a software professional, for the longest time I didn’t really have any sort of version control as part of the process. I did local development and just piece meal copied files to the production; please don’t tell anyone or send anyone to this posting who will hold this against me. This process eventually became cumbersome, and combined with the desire for a secondary backup of some sort, I implemented the following using BitBucket as the secondary backup.
The main schematic looks somewhat like this
Webfaction (production) <—-> Bitbucket (staging/ backup) <—> Local (development)
The following assumes an existing Django project has been set up on Webfaction, but could be adapted.
On Webfaction – Create and populate the Git repository
At project root (e.g. webapps/myproj)
- git init
- create .gitignore (I populate it as follows)
- *.pyc
- settings.py
- *.wsgi.py
- /bin/
- /apache2/
- git add .
- git commit -m ‘Commit Message’
On Bitbucket
Create Bitbucket repository (e.g named myrepo)
From root in WebFaction, push the code to Bitbucket
- git remote add origin https://trhdata@bitbucket.org/trhdata/myrepo.git
- git push -u origin –all # pushes up the repo and its refs for the first time
- git push origin –tags # pushes up any tags
Now to move from Bitbucket to a local copy, we clone the Bitbucket repo
I use the Sourcetree software available on BitBucket for this
Clone Bitbucket myrepo.git to c:\myproj_git (your choice of directory name)
On local machine
- Move in and edit a local Django settings file (settings.py has been excluded in .gitignore)
- In Sourcetree, create a new branch, branch1, and change to it (essentially a Git checkout)
- Make changes to branch1 and test
- Commit the changes in branch1
- Merge branch1 into master (switch to master and merge in branch1)
Push into Bitbucket
This can be done from SourceTree
Deploy from Bitbucket to Webfaction (deploy to production)
On Webfaction, we have a repo named master and a remote named origin, which is set up as our BitBucket repo, so we can do the following
git pull origin master
Now restart apache and everything should be good !