Adding and Deleting Remote Branches

Any new development you create on branches in your local clone is not visible in the parent repository until you make a direct request to propagate it there. Similarly, a branch deletion in your repository remains a local change and is not removed from the parent repository until you request it to be removed from the remote as well.

In Chapter 7, you learned how to add new branches and delete existing ones from your repository using the git branch command. This command operates only on a local repository.

To perform similar branch add and delete operations on a remote repository, you need to specify different forms of refspecs in a git push command. Recall that the syntax of a refspec is:

[+]source:destination

Pushes that use a refspec with just a source ref (i.e., no destination ref) create a new branch in the remote repository:

$ cd ~/public_html

$ git checkout -b foo
Switched to a new branch "foo"

$ git push origin foo
Total 0 (delta 0), reused 0 (delta 0)
To /tmp/Depot/public_html
 * [new branch]      foo -> foo

Pushes that use a refspec with just a destination ref (i.e., no source ref) cause the destination ref to be deleted from the remote repository. To denote the ref as the destination, the colon separator must be specified:

$ git push origin :foo
To /tmp/Depot/public_html
 - [deleted]         foo

Get Version Control with Git now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.