-
Notifications
You must be signed in to change notification settings - Fork 7
Creating and using branches with Git
When working with a repository on your local machine you need to keep your master branch clean.
Ideally, every time you want commit a bug or a feature, you should create a branch for it, which will be somehow the copy of your master branch.
This way, when you perform a pull request on a branch, you can continue to work on another branch and make another pull request on that other branch.
Before create a new branch pull the changes from upstream, your master need to be up to date.
Create the branch on your local machine :
$ git branch <name_of_your_new_branch>
Push the branch on github :
$ git push origin <name_of_your_new_branch>
Switch to your new branch :
$ git checkout <name_of_your_new_branch>
When you want to commit something in your branch, be sure to be in your branch.
You can see all branches created by using
$ git branch
Which will show :
* approval_messages
master
master_clean
Add a new remote for you branch :
$ git remote add <name_of_your_remote> <url>
Push changes from your commit into your branch :
$ git push origin <name_of_your_remote>
Delete a branch on your local filesytem :
$ git branch -d <name_of_your_new_branch>
Delete the branch on github :
$ git push origin :<name_of_your_new_branch>
Note: ':' tells git to delete the branch.
If you want to change default branch, it's so easy with github, in your fork go into Admin and in the drop-down list default branch choose what you want.
The contents for this brief walkthrough were originally obtained here.