-
Notifications
You must be signed in to change notification settings - Fork 60
Work With Git Branches
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.
-
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
-
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. -
You can use the checkout command to switch between branches as required.
-
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 justgit 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.