Skip to content

Work With Git Branches

OmniBlade edited this page Apr 24, 2020 · 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 development branch so ensure that is checked out first with the following command:
    git checkout develop

  2. You can 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.

  3. You can use the checkout command to switch between branches as required.

  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" the remote and branch name to use from then on. 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.