git ready

learn git one commit at a time
by Nick Quaranto

push and delete remote branches

committed 02 Feb 2009

This is an action that many Git users need to do frequently, but many (including the author) have forgotten how to do so or simply don’t know how. Here’s the definitive guide if you’ve forgotten.

So let’s say you have checked out a new branch, committed some awesome changes, but now you need to share this branch though with another developer. You can push the branch up to a remote very simply:

git push origin newfeature

Where origin is your remote name and newfeature is the name of the branch you want to push up. This is by far the easiest way, but there’s another way if you want a different option. Geoff Lane has created a great tutorial which goes over how to push a ref to a remote repository, fetch any updates, and then start tracking the branch.

Deleting is also a pretty simple task (despite it feeling a bit kludgy):

git push origin :newfeature

That will delete the newfeature branch on the origin remote, but you’ll still need to delete the branch locally with git branch -d newfeature.

There’s a script called git-publish-branch created by William Morgan that can easily automate this process if you find yourself performing these actions frequently. It also makes deleting remote branches feel a bit more natural. Know of better or easier ways to do the above tasks? Let us know in the comments or submit your own tip!

blog comments powered by Disqus


smartly save stashes remote tracking branches ignoring doesn't remove a file where to find the git community finding who committed what what git is not how git stores your data converting from svn tagging push and delete remote branches installing git branching and merging pushing and pulling ignoring files the staging area cleaning up untracked files reverting files stashing your changes


find unmerged commits find ancestor commits restoring a directory from history rolling back changes with revert pick out individual commits get a file from a specific revision temporarily ignoring files list remote branches easily fetching upstream changes reflog, your safety net helpful command aliases intro to rebase finding what has been changed exporting your repository text-based graph sharing your changes count your commits interactive adding visualizing your repo checkout tracked remote branch


ribbon/catchup: reading new commits tig, the ncurses front-end to Git what's inside your .git directory reorder commits with rebase easily manage git remote branches keep either file in merge conflicts convert git-svn tag branches to real tags pull with rebase squashing commits with rebase bash auto completion push to only bare repositories zsh git status bash git status bend logs to your will restoring lost commits piecemeal staging fixing broken commit messages


Git Community Book GitHub Guides GitWiki GitCasts Git for everyone Git-SVN Crash Course $ cheat git Why Git is Better Than X Git for Computer Scientists Git Magic Gitology gitguru Pro Git Book Git Reference A tour of git: the basics Git from the bottom up Git Immersion Git Guys
about code submit a tip rss twitter
available in: dutch | french | german | hebrew | italian | japanese | korean | portuguese | spanish | swedish | russian | your language?
spacer is neither affiliated with the authors of this page nor responsible for its contents. This is a safe-cache copy of the original web site.