We’re just starting to use GIT at Defensio and although there are plenty of great resources like the Peepcode video and Jean-François Couture’s blog, the learning curve (from SVN) can be a little rough. The problem is that GIT is very powerful, and probably too powerful for a small shop like ours. This unfortunately leads to some complexity that we’d rather not have to deal with, especially since we don’t need all the fancy features.
In an effort to simplify our workflow, we started to build a few scripts that automate complex tasks. My plan is to post them on my blog for your own benefit. If they’re useful for us, they should be useful for other people too.
The first script I’m posting is git-remote-branch. It is meant to simplify the process of creating and deleting remote and local tracking branches. Instead of having to execute multiple commands, easy to remember one-liners are now enough. (hey! we’re lazy!)
Check this out:
git-remote-branch create experimental
This command creates an experimental branch on a remote server (‘origin’ by default) from the one you’re currently sitting in, then a local tracking branch. When that’s done, it checks out to the newly created local branch. You can then pull and push as you wish.
git-remote-branch create experimental origin2
This command does the same as the previous one, but creates experimental on ‘origin2′ instead of ‘origin’.
When you’re done dealing with the remote/local branch combo you created, you can delete both in one go:
git-remote-branch delete experimental
The script will delete the remote branch, then check out “master” if you’re still sitting in “experimental”. The local “experimental” branch is then deleted.
git-remote-branch can be downloaded here. Make sure to chmod +x it before executing it. For the record, it’s written in Ruby. Let me know if it’s useful for you!
27/01/2008 at 5:50 pm Permalink
That looks really useful! Deleting remote branches is rather cryptic in git right now, so this will help.
27/01/2008 at 7:22 pm Permalink
Nice work! It’s true that git out of box might not have all the niceties required for small shops, working with a central server. But git is so powerful it’s easy to script a little something like this!
27/01/2008 at 8:13 pm Permalink
Geoff, J-F: thanks for the kind words. I hope to write more of those small quick-n-dirty scripts in the future. This one has been of a lot of help so far for me.
06/02/2008 at 5:27 pm Permalink
Thank you for posting this script. Similar to the form that exists for git-remote-branch-create, does git-remote-branch-delete also have a more general form that can delete a given branch from any given remote Git repo?
06/02/2008 at 5:33 pm Permalink
I reviewed the script again and found that git-remote-branch-delete does allow you to specify the remote name just as you can with git-remote-branch-create.
06/02/2008 at 6:03 pm Permalink
Does Git allow you to delete all branches from a remote repo, including the master branch? I ask because I’d like to delete the master branch of a project at repo.or.cz because repo.or.cz allows one to delete neither an entire project nor the Git repo of a project.
06/02/2008 at 6:06 pm Permalink
By the way, I just verified that Git does not allow one to delete all branches from a *local* repo. Once you’ve committed the first commit to the initial branch (default is ‘master’), it seems that you cannot delete this branch. I suppose this makes sense because it would be very dangerous to allow a user to delete the entire main history of a repo. It follows from this reasoning that Git should also disallow the deletion of all branches in a remote repo, but I haven’t yet verified that this is true.
06/02/2008 at 6:07 pm Permalink
My guess is that you can’t delete the master branch. Why would you want to do so anyways?
06/02/2008 at 8:35 pm Permalink
I want to delete the master branch on a remote repo at repo.or.cz because repo.or.cz does not appear to allow one to delete a project or to delete the Git repo that it associates with a project. If I could re-create the master branch, I could get around this shortcoming. Otherwise, I’ll just avoid repo.or.cz in favour of some other Git hosting service or host the repo on my own site, though it wouldn’t be as visible (findable) as on a well-known hosting service.
13/06/2008 at 11:50 am Permalink
Great script, but I noticed a small bug. If you call it with no arguments you get some errors instead of the excepted usage message.
But I managed to fix it by changing
action = get_action
branch = get_branch
to:
action = get_action if ARGV[0]
branch = get_branch if ARGV[1]
13/07/2009 at 6:54 am Permalink
I don’t get it, what do you mean by the 3rd paragraph?