O'Reilly logo

Version Control with Git by Jon Loeliger

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required