Making more branches
This section will guide you through how to create more branches, taking the main branch you created as a base.
When you create a Git project, it will automatically create a “main” (sometimes “master”) branch for you. This is where the code that has been QA’d and you are happy with should sit.
It is good practice to create a branch whenever you have a change to make to your work. Having two branches means that if anything goes wrong in the “development branch”, the “main” branch is still unaffected and runs without issue. This lets you test and QA the code more thoroughly before merging into your main branch.
Chose one method below to create your new branch, which we will call “development”. Then follow the instructions at the bottom of this page to update your logbook.
- Ensure you’re on your own personal main branch that you created in making a branch. If you aren’t sure use:
git checkout -b <github_username>/main
- Pull the latest changes from the remote repository.
git pull origin <github_username>/main
- Create your new development branch
git checkout -b <github_username>/development
- Push the new branch to the remote repository:
git push -u origin <github_username>/development
- Check that the new branch shows in the branch list.
git branch
Ensure you are on your personal main branch.
In the Git panel, click the purple new branch symbol
as to the left of the username in the screenshot below.
Then enter your development branch name as
<github_username>/development
(but replacingwith your own GitHub username, e.g. jsmith_development
)
Click Branch in the menu bar and then select New branch… as shown in the screenshot below.
Then enter your branch name as
<github_username>/development
(but replacingwith your own GitHub username, e.g. jsmith_main
)
The current branch
(<github_username>main)
should be listed in the very bottom left hand corner of the VS Code window frame. If you left click on this, you should then see a menu appear at the top of the VS Code window with some branch options (as shown in the screen shot below).Click + Create new branch… and then enter your branch name as
<github_username>/development
(but replacingwith your own GitHub username, e.g. jsmith_development
).You should now see the branch name listed in the bottom left of the window frame shown as the branch you just created, meaning any changes you currently make will be applied to that new development branch (and not the main branch, or your personal main branch).
Open up the Git panel in PyCharm and you should see something like the screenshot below. Right click on your
<github_username>/main
branch and select New branch from ‘<github_id>/main’….Then enter your branch name as
<github_username>/development
(but replacingwith your own GitHub username, e.g. jsmith_development
).
Now you have made your development branch, go to your git log and update tick the ‘making a development branch’ box. Use the recording changes section for a reminder on how to make and save changes. Ensure to commit and push your changes.