5.4. Git
Git can be used for version control.
Minimal set up:
git config --global user.name "Your Name"
git config --global user.email youremail@example.com
Optional git aliases:
git config --global alias.co checkout
git config --global alias.br branch
git config --global alias.ci commit
git config --global alias.st status
Note
For Django, remove the secret key from settings.py and put it into local_settings.py. Just in case you make your project public in the future you need to minimise security risks.
5.4.1. Existing Project
If you already have a project on BitBucket you can:
git clone git@bitbucket.org:USER/PROJ_NAME.git
cd project
# To install required packages:
pip install -r requirements.txt
# For Django projects:
python manage.py migrate
5.4.2. New Project
From within your project folder:
git init
5.4.2.1. Files to ignore
Note
For Django, remove the secret key from settings.py and put it into local_settings.py. Just in case you make your project public in the future you need to minimise security risks.
Add files to be ignored and not stored in version control by typing nano .gitignore in the project root:
*.pyc
*.pyo
db.sqlite3
*.db
.DS_Store
local_settings.py
/static
/proj_name/static/media/
*~
*.kate-swp
/venv
# Add others you do not want storing
5.4.2.2. Initial commit
Create a project on BitBucket and follow the instructions for adding it as the origin for git. Also add the SSH key for development machine.
git add .
THEN
git commit -m "Initial commit"
OR
git commit -am "Initial commit"
git remote add origin git@bitbucket.org:USER/proj_name.git
OR
git remote add origin https://PROJ@bitbucket.org/PROJ/REPO.git
git push -u origin master
5.4.3. Branches
Note
The default initial branch is master which is now considered insensitive so it is common place to rename the master branch to main or stable.
When you are working with the code you can create and merge branches before uploading the latest code to BitBucket:
git branch dev
THEN
git checkout dev
OR
git checkout -b dev
EDIT PROJECT CODE
git status
git add .
git commit -m "A note about the code changes made."
git checkout main
git merge dev
git push -u origin main
git push origin :newfeaturebranch # Delete remote branch
git branch -d newfeaturebranch # Delete local branch
Remove files:
git rm file1.txt
git commit -m "remove file1.txt"