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
- After, you should have got similar directory tree with .git folder inside:
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 email@example.com
Prepare project for pushing to Github
4. 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.
5. Create requirements.txt file. It will be helpful to install all dependencies:
(todowoo) revorete@E7440:~/todowoo_project_drf$ pip freeze > requirements.txt
6. 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
7. Stage/track all files (without those in .gitignore):
$ git add .
If you want to stage/track only one file:
$ git add <filename>
8. In case you want to unstage a file:
$ git rm --cached <filename>
9. Commit changes:
$ git commit -m "First commit"
Push code to Github
10. Create new repository on Github. Click new repository and create a public one:
11. 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
$ git remote add origin firstname.lastname@example.org:croolicjah/todowoo-project-drf.git
12. Finally, push changes:
$ git push -u origin master
Well done. Check Github. Your repository is there.