Skip to content

Instantly share code, notes, and snippets.

@americkson
Last active September 6, 2016 03:43
Show Gist options
  • Save americkson/5196021 to your computer and use it in GitHub Desktop.
Save americkson/5196021 to your computer and use it in GitHub Desktop.
GIT - Working with branches

Create a branch:

$ 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>

The only difference it's the : to say delete.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment