Skip to content

Work With Git Branches

OmniBlade edited this page Feb 12, 2021 · 1 revision

Branches allow you to separate development into chunks and experiment easily while giving the safety net of being able to restore the source tree quickly to an earlier state to develop separate features in parallel. You should avoid committing your changes directly to your copy of the main development branches (normally the "develop" branch) and instead keep that up to date with upstream as a reference branch for operations like rebasing or as the basis for new development branches of your own.

Using Branches

  1. Once you have your local repository cloned from Github, you should create new branches to do your actual development on. This should normally be done based on the main development branch so ensure that is checked out first with the following command:
    git checkout vanilla

  2. You can now create and checkout a new branch based on the branch you are currently on with the following command:
    git checkout -b newbranchname
    The new branch will be exactly the same as the branch you had checked out originally at this point but changes to it will not affect the original.

  3. You can use the checkout command to switch between branches as required. You can have as many branches as you want if you are developing multiple features.

  4. You can push a branch to your Github copy of the repository with the following command:
    git push -u origin newbranchname
    Here the -u option will make it easier to push in future for this branch with just git push once you commit some new code to it as it makes it remember or "track" the remote and branch name to use from then on for this branch. The "origin" part is the name of the remote you want to push to and if you cloned from your fork it will be the default name to use. If you followed the guide on working with forks, you will also have an "upstream" remote which points at the main repository for the project.

Clone this wiki locally