Preparing project to deploy and pushing it to Github
Written by Resident Baller:
croolic
Before deploying your project it's worth pushing it to any VCS (Version Control System). We are going to use very popular Github. I assume that you've installed Git. If not follow this guide: Installing Git. In this guide I use Linux system and terminal. There should be no difference for Mac Os users. Windows users should use Git bash.
Create git repository inside your project
1. Go to your project root directory and init git repository:
$ git init
2. After, you should have got similar directory tree with .git folder inside:
todowoo-project-drf
āāā api/
āāā .git/
āāā media/
āāā todo/
āāā todowoo/
āāā db.sqlite3
āāā .gitignore
āāā manage.py
āāā Procfile
āāā requirements.txt
3. If you haven't do it before configure your git by running commands:
$ git config --global user.name "Jacek Ka."
$ git config --global user.email jacek.ka@example.com
Prepare project for pushing to Github
3. Hide sensitive data which are not going to be pushed into Github. In Django projects you should hide SECRET_KEY, database credentials, any tokens etc. How to do that you find here: Secret should be kept secret. You can use as well packages like django-environ or python-decouple.
4. Create requirements.txt file. It will be helpful to install all dependencies:
(todowoo) revorete@E7440:~/todowoo_project_drf$ pip freeze > requirements.txt
5. Create .gitignore in the root project directory and add there files not to track e.g. .evn files, .idea/ directory. To generate it would be a helpful gitignore.io site. This file could look like:
### Django ### *.log *.pot *.pyc __pycache__/ **/__pycache__/ local_settings.py db.sqlite3 db.sqlite3-journal media
6. Stage/track all files (without those in .gitignore):
$ git add .
If you want to stage/track only one file:
$ git add <filename>
7. In case you want to unstage a file:
$ git rm --cached <filename>
8. Commit changes:
$ git commit -m "First commit"
Push code to Github
9. Create new repository on Github. Click new repository and create a public one:
10. Go to terminal on a local computer and add a remote repository. The git remote add command takes two arguments:
- A unique remote name, for example “origin”
- A remote URL, which you can find on the Code sub-tab of your Git repo
$ git remote add origin https://github.com/croolicjah/todowoo-project-drf.git
or:
$ git remote add origin git@github.com:croolicjah/todowoo-project-drf.git
11. Finally, push changes:
$ git push -u origin master
Well done. Check Github. Your repository is there.