The next step you need to take before actually contributing is creating a new branch for your change.
Branches allow you to create a local copy of the repository at its current state, which you can later merge into the master
branch. But why would we want to do this?
Put simply, using separate branches as workspaces allows for the master
branch to be the point of reference for all contributors in the project. The master
branch should be a stable and functioning version of the project at all times. Creating separate branches for separate features allows you to make changes, test them, and push them to GitHub without ruining the stable version of the product.
Using branches also allows for implementations features to be organized well and later merged to the master
branch piece by piece rather than in one large chunk of code. For example, if you have working code for a basic game of Pong and want to add more features, contributors might create a branch to implement different ball colors, one for different background colors, and one for different fonts. If the contributor working on the background colors gets done first, they can merge those changes into the master
branch without having to wait for the people working on the other features to finish. This becomes especially important as the number of project contributors grows.
Branches are also needed for creating Pull Requests, which we'll discuss in depth later. The importance of branches in PRs have to do with making changes. When you submit a PR (pull request) for you branch to be merged to the master
, normally the owner(s) of the repository will check the code to make sure that the code is written well and does what it's supposed to. If you submit your branch in a PR and changes are requested, all you need to do is push the changes to your branch and the changes will automatically show up in the PR. Again, we'll talk more about it later, but this is an important part of branches.
git checkout -b <branch_name>
where <branch_name>
is up do you.
git branch
in your shell. The branch you are currently on will be highlighted.
git checkout <branch_name>
where <branch_name>
is the name of the desired branch.
When starting a fresh feature, first make sure your master branch is up to date, then create your new branch! To learn how to actually change the code and add the changes to your branch, see the next section.
Create a branch with your last name titled lastname-first-branch
and go into it. Use git branch
to check.