GitHub
Setup
To set up GitHub for a new project see the Installation section.
Branches - new project features
It is a good practice to create a new branch for each new feature you work on in your Django project. This allows you to work on the feature independently without affecting the main codebase, and also provides a clean way to merge the changes into the main branch once they are ready.
Step 1: create a new branch
git checkout -b new-feature
Step 2: add and test the new feature
Step 3: add commits
git add .
git commit -m "Implemented new feature"
Step 4: push all changes to the 'new-feature' branch on the remote repository
git push -u origin new-feature
Step 5: create a pull request
- Go to your repository on GitHub
- Click on the "Pull Requests" tab
- Click the "New pull request" button
- Select the new-feature branch as the "compare" branch
- Select the main branch as the "base" branch
- Review the changes in the pull request
- Click the "Create pull request" button
Step 6: review and merge the pull request
- Click the "Merge pull request" button
- Select "squash and merge" to keep your commit history clean
- Write a descriptive commit message that summarizes the changes made in the pull request
- Click the "Confirm squash and merge" button
Step 7: update your local main branch
git checkout main
git pull origin main
Step 8: delete the remote new-feature branch on the remote repository
git push origin --delete new-feature
Step 9: delete the remote new-feature branch on the local repository
git branch -d new-feature
Clone a repository from GitHub to a local machine
Copy url: go to the repository on GitHub, click on code, and copy the URL
Clone repository: inside the directory where you want to store your locl copy open terminal and use the following command
git clone _your_repository_url_
Commit & Push:
git add .
git commit -m "my_commit_message"
git push origin main
GitHub Pages
Host a static page on GitHub for free
- Go to https://github.com/
- Create a new repository and give it a name
- Select "Public" and "Add a README file" and click the "Create repository" button
- Click on "Add file", upload your page files and commit changes
- Go to Settings and then select Pages
- Select the "None" dropdown menu and choose your "main" branch as the source
- The address will be: https://_your_username_.github.io/_repository_anme_/
Useful commands
- git clone repository_url: Clones a repository from GitHub to your local machine.
- git status: Shows the status of your local repository, including any changes made to the files.
- git add .: Adds all changes made to all files or directoris to the staging area, preparing them to be committed.
- git commit -m "commit_message": Commit all changes and add a message describing the changes.
- git push remote branch: Pushes the committed changes to the remote repository.
- git pull remote branch: Pulls the latest changes from the remote repository to your local repository.
- git branch new_branch_name: Creates a new branch with the specified name.
- git checkout branch_name: Switches to the specified branch.
- git merge branch_name: Merges the specified branch into the current branch.
- git log: Shows a log of all the commits made to the repository, including the commit message, author, date, and commit hash.