Programblings

Rambling about programming and life as a programmer - by Mathieu Martin

Archive for the 'git_remote_branch' Category


git_remote_branch is github-agnostic

17th November 2008

Josh Knowles recently suggested that maybe I could merge grb’s functionality to the github gem.

Both gems being command-line tools that help you use Git in a friendlier manner, the question makes a lot of sense. It makes so much sense in fact, that I decided to blog about it. A post about it will scale much better to answer other users who may potentially ask the same question.

So here’s a slightly edited excerpt from the answer I gave him. And yes, I also ramble in email.

I’ve seen what Scott added to the github gem. Pretty cool stuff indeed. I think the idea of merging with the github gem has merit. I definitely can see a future where we start having too many distinct command-line tools that help deal with Git’s sometimes obscure or numerous commands.

However I’m not sure I’d like to merge grb into the gh gem, despite the additional awareness it would get. Here’s why.

In my mind, the github gem should be mostly features about GitHub itself, like managing pull requests (the way GitHub does them). It’s starting to accumulate features that probably aren’t GitHub-specific, which I don’t mind, of course. But grb’s features really are GitHub-agnostic. I’ve started working on it before I even started using GitHub, in fact :-)

Reinforcing the previous point, I wouldn’t want someone who doesn’t use GitHub to not realize the features of grb are available to him because they’re included in a gem called ‘github’ ;-)

Also, one of the goals of git_remote_branch is to explicitly teach the underlying git commands. I do this by always spewing out the underlying commands in red, and by having the explain command. I’m pretty sure an unsuspecting user would wonder what hit him if a few of the github commands started spewing out red text in his console ;-) Having explain for a few commands (ported from grb) and not for the rest of the github gem’s commands would be weird, too.

There’s also a few other architectural decisions of grb that may not fit with github’s, like having aliases. Once again, grb being a teaching tool, I want to offer a bunch of aliases for forgetful people like me. So far I don’t see anything like aliases in github and I’m not sure how the authors of github-gem would react to a pull request polluting it with a bunch of aliases ;-)

Last but not least, the github gem already has a track command, which conflicts with grb’s. github’s is used to track a new remote repo in your local repo while grb’s is to track another branch from your current remote repo.

So git_remote_branch is GitHub-agnostic. You can use it with any Git hosting solution: GitHub, your own Gitosis / gitweb / Gitorious installation, Gitorious.org hosting, Rubyforge or any other.

Better, grb supports working with all of them at the same time. All grb commands support an optional origin argument.

Learn more about git_remote_branch

Posted in git_remote_branch | No Comments »

git_remote_branch 0.3 - Awesomeness for the masses

14th November 2008

Awesomeness for the masses

git_remote_branch 0.3 has been released!

Previous releases were pretty much only usable by rubyists on OS X.

Works on my machine logo

No more. This release is mostly focused on making sure git_remote_branch works on a broader range of platforms. A few actual features squeaked in, but nothing big like introducing new commands.

If you don’t care about the details just type the following at your command-line.

sudo gem install git_remote_branch

And check the help

grb --help

If you encounter installation problems, refer to the readme.

Platforms

git_remote_branch 0.3 has been tested with the following configurations:

  • OS X Leopard / Ruby 1.8.6 / Git 1.5.4.3 and 1.6.0.2
  • OS X Leopard / Ruby 1.9.1 / Git 1.5.4.3 and 1.6.0.2
  • Ubuntu Intrepid Ibex / Ruby 1.8.7 / Git 1.5.6.3
  • Windows XP / Ruby 1.8.6 / Git 1.6.0.2 (the msys version)

Features

Better track

Track now works even if you already have a local branch of the same name. It uses git config instead of branch —track in that case. The subtlety can be observed by running (from a git repository):

grb explain track master
grb explain track non_existent_branch

Force the use of a specific git executable

Set the environment variable GRB_GIT to point to it and grb will use this one for all its operations.

Documentation

I’ve also worked quite a bit on the actual documentation. I used to be ashamed at the quality and availability of the documentation of git_remote_branch. At last I’ll be able to sleep at night :-)

git_remote_branch in a nutshell

I’ve rewritten the intro of the readme to be (hopefully) a bit clearer.

git_remote_branch is a simple command-line tool that makes it very easy to manipulate branches published in shared repositories.

It achieves this goal by sticking to a few principles:

  • keep grb’s commands extremely regular (they all look alike)
  • support aliases for commands
  • print all commands it runs on your behalf in red, so you eventually learn them

Another nice thing about git_remote_branch is that it can simply explain a command (print out all the corresponding git commands) instead of running them on your behalf.

Note: git_remote_branch assumes that the local and
remote branches have the same name. Multiple remote
repositories (or origins) are supported.

Documentation availability

The main readme is now available on the main grb page on rubyforge.

Documentation quality

I’ve added clearer information on getting grb to run in different kinds of situation, due to helpful feedback from Axelson and Glenn Rempe.

I’ve also added some information for playing with the code for git_remote_branch (test dependencies and so on). See the end of the readme.

Finally, I’ve updated the links section quite a bit:

Documentation http://grb.rubyforge.org
News http://programblings.com/category/git/git_remote_branch/
Bug tracker Lighthouse
Code http://github.com/webmat/git_remote_branch
Mailing list http://groups.google.com/group/git_remote_branch

Dare

I dare you to find a platform on which git_remote_branch doesn’t work :-)

If you do, please send me feedback through GitHub or via email. I’m using gmail and, as usual, I go by the handle of webmat.

Last note: the git_remote_branch gem on GitHub

Excerpt from the readme:

Note that the only stable version of the gem you should trust is the one from Rubyforge. The GitHub gem is a development gem. The GitHub gem WILL be rebuilt with the same version number, and other horrible things like that. If you use the GitHub version of git_remote_branch, children will die!

You’ve been warned.

Posted in garbage in, garbage out, git_remote_branch | No Comments »

Time to git collaborating with git_remote_branch

6th August 2008

git_remote_branch 0.2.6 is out!

I’ve just released a new and improved version of git_remote_branch. Code named 0.2.6!

Ok, I admit. I haven’t really begun using code names.

I’m promoting the project from a pre-alpha to an alpha release. There’s still a lot to do, but the stability and “testedness” have improved greatly. Following are both sides of the maturity story.

The project is maturing

  • grb got its first contributor, Caio Chassot
  • I added a lot of tests, both unit and functional
    • there might even be interesting stuff to see in there for those who need to test command-line tools
  • the gem can now be installed directly from RubyForge
  • git_remote_branch now has a Google Group

The project is still immature

  • it swears a lot
  • no rubyforge page, despite the project being on rubyforge (at rubyforge.org/projects/grb)
  • no real documentation other than running grb help
  • very little in code documentation. On the other hand the code is spectacularly clean and readable, so that’s completely unnecessary. Just kidding.

What’s new in 0.2.6?

Three new actual features

  • the ‘rename’ command, contributed by Caio Chassot
  • the ‘publish’ command
  • the −−silent option to completely mute grb output as well as every git command run by grb on your behalf

And other stuff

  • the grb bin file now works when symlinked (also thanks to Caio Chassot)
  • lots of unit and functional tests
  • bug fixes
  • more flexibility for running grb outside of a git repository (e.g. for ‘explain’ or ‘help’)
  • now officially under the MIT license
  • refactored a bunch of rake tasks

Git the new version

To install the newest version of the gem, simply run

sudo gem install git_remote_branch

If you really want to be on the bleeding edge you can also get it on GitHub. Note however that in ‘bleeding edge’ the word ‘bleeding’ is still the most important one at that point.

git clone git://github.com/webmat/git_remote_branch.git
cd git_remote_branch
rake install

The ‘install’ task will run the tests before installing so you’ll need Shoulda, mocha, redgreen and ruby-debug for that approach.

Not familiar with git_remote_branch?

What it is

The basic idea for git_remote_branch is to trivialize the interaction with remote branches. The first goal is to make the commands for the simple situations easy.

The secondary goal, is to help you learn the commands by seeing them displayed in a beautiful shade of red each time you use grb, along with git’s output.

git_remote_branch lets you

  • create local-remote branche pairs, and tracks the remote branch automatically (for automatic merges when you git pull)
  • publish a local branch as a remote branch, very similar to create
  • delete local-remote branch pairs
  • track a remote-only branch
  • rename a local-remote branch pair
  • explain by simply spitting out the necessary commands to do any of the above

How to use it

explain

If you simply want to use grb as a cheatsheet (and run nothing on your behalf), you can use the explain command:

$ grb explain create
git_remote_branch version 0.2.6

List of operations to do to create a new remote branch and track it locally:

git push origin current_branch:refs/heads/branch_to_create
git fetch origin
git branch −−track branch_to_create origin/branch_to_create
git checkout branch_to_create

or

$ grb explain create my_branch my_origin
git_remote_branch version 0.2.6

List of operations to do to create a new remote branch and track it locally:

git push my_origin current_branch:refs/heads/my_branch
git fetch my_origin
git branch −−track my_branch my_origin/my_branch
git checkout my_branch

Notice that you can specify any normally expected parameter you’d normally include and ‘explain’ will use them in the list of commands it suggests.

Even better, if you’re in your repository, the current branch is going to be taken into account:

(master) $ grb explain create my_branch my_origin
git_remote_branch version 0.2.6

List of operations to do to create a new remote branch and track it locally:

git push my_origin master:refs/heads/my_branch
git fetch my_origin
git branch −−track my_branch my_origin/my_branch
git checkout my_branch

Of course, ‘explain’ works for all commands: create, publish, delete, track and rename.

The main commands

I’m not going to painstakingly give an example for each command. I’ll only give two, to show how git’s responses are displayed when running grb without ‘explain’:

(master)$ grb create test_branch
git_remote_branch version 0.2.6

git push origin master:refs/heads/test_branch
Total 0 (delta 0), reused 0 (delta 0)
To git@github.com:webmat/git_remote_branch.git
 * [new branch]      master -> test_branch

git fetch origin

git branch −−track test_branch origin/test_branch

git checkout test_branch
Switched to branch "test_branch"

(test_branch)$ grb delete test_branch
git_remote_branch version 0.2.6

git push origin :refs/heads/test_branch
To git@github.com:webmat/git_remote_branch.git
 - [deleted]         test_branch

git checkout master
Switched to branch "master"

git branch -d test_branch

(master) $ 

Yes my friends, I have just boldly used grb on my real repository for your viewing pleasure.

But worry not, no repository was hurt during the writing of this article.

Feedback

For any feedback you’re of course welcome to

Thanks

Posted in blogging, garbage in, garbage out, git, git_remote_branch, programming | 2 Comments »

Git remote branches

23rd June 2008

I’m ready to bet that setting up and deleting remote branches is something you do rarely enough that you always find yourself looking up the documentation. Or maybe it’s just me.

Due to its roots, Git supports a wide array of usage scenarios for interacting with remote repositories, and we love it that way. It’s a big factor in the flexibility and power of the tool.

However in simple scenarios, there’s still a bunch of commands you must run to accomplish simple tasks. I believe the commands for the simple scenario can be simpler.

Last January, Carl Mercier created git-remote-branch. I’ve found this script very useful and, with his permission, I’ve decided to keep moving it forward and add a few features to it.

git_remote_branch

The first purpose of git_remote_branch is to encapsulate all the commands that need to be run to interact with remote branches in simple scenarios.

Its second purpose is to be a learning tool. git_remote_branch does two things to help you learn these commands:

  • It clearly displays the commands it runs on your behalf, in a beautiful shade of red;
  • It has an ‘explain’ meta-command that will simply display the list of commands instead of running them for you.

Examples

Help

Let’s start with the simplest of all:

$ grb

or

$ grb help
git_remote_branch version 0.2.2

  Usage:

  grb create branch_name [origin_server]

  grb delete branch_name [origin_server]

  grb track branch_name [origin_server]

  If origin_server is not specified, the name 'origin' is assumed (git's default)

  The explain meta-command: you can also prepend any command with the keyword 'explain'.
  Instead of executing the command, git_remote_branch will simply output the list of commands
  you need to run to accomplish that goal.
  Example:
    grb explain create
    grb explain create my_branch github

  All commands also have aliases:
  create: create, new
  delete: delete, destroy, kill, remove
  track: track, follow, grab, fetch

As you can see, the syntax for all commands is very regular: action, branch_name and optionally, origin_server.

To facilitate learning even more, aliases are also provided. So to take an example,

$ grb track his_branch

and

$ grb fetch his_branch

are perfectly equivalent.

create

Create lets you create a new branch both remotely and locally. Note that it’s not made to share an existing branch (that feature’s coming).

So what it does is to push your current branch as a new remote branch, then create it locally and track it, for easier pulling afterwards.

$ grb create some_branch
git_remote_branch version 0.2.2

git push origin master:refs/heads/some_branch
Total 0 (delta 0), reused 0 (delta 0)
To /path/to/repo/
* [new branch]      master -> some_branch

git fetch origin

git branch −−track some_branch origin/some_branch

git checkout some_branch
Switched to branch "some_branch"

delete

Presenting features with names that are too self-evident is boring. Let’s get to the point, already.

$ grb delete some_branch
git_remote_branch version 0.2.2

git push origin :refs/heads/some_branch
To /path/to/repo/
- [deleted]         some_branch

git checkout master
Switched to branch "master"

git branch -d some_branch

track

Track lets you easily track the changes that are made to an existing remote branch you’re not tracking already. Each time you pull from the remote repository, the local branch will be automatically merged with the remote branch.

$ grb track his_branch
git_remote_branch version 0.2.2

git fetch origin
From /path/to/repo/
* [new branch]      his_branch -> origin/his_branch

git branch −−track his_branch origin/his_branch

explain

Explain will spew out all commands necessary to accomplish one of the previous actions. There are two ways of using it. The simplest will give you dummy commands:

$ grb explain create
git_remote_branch version 0.2.2

List of operations to do to create a new remote branch and track it locally:

git push origin master:refs/heads/branch_to_create
git fetch origin
git branch −−track branch_to_create origin/branch_to_create
git checkout branch_to_create

Or you can have steps that are tailor-made for what you want to accomplish.

$ grb explain create my_branch github_origin
git_remote_branch version 0.2.2

List of operations to do to create a new remote branch and track it locally:

git push github_origin master:refs/heads/my_branch
git fetch github_origin
git branch −−track my_branch github_origin/my_branch
git checkout my_branch

get git_remote_branch

(Hey, this title has a nice ring to it)

sudo gem install webmat-git_remote_branch −−source=http://gems.github.com

Now with rubygems 1.2.0 out (don’t do it with a prior version), you can also add GitHub as a permanent source for your gems:

sudo gem sources -a http://gems.github.com

Now and ever after, you will be able to get anything from GitHub with a simple

sudo gem install webmat-git_remote_branch

If in your eagerness you’ve added github as a source before running

sudo gem update −−system

Please refer to What to do when gems.github.com breaks gems FOREVAR

Look ma, no tests!

Uhhhh, yeah, I know…

This tool is still extremely early in its life and - dare I say it - it’s only hand-tested for now. I’ve been using it personally for a while and it’s working very well for me, if that means anything :-)

So this is still a quick script, only now it has lipstick.

Works on my machine logo

This software should be considered an early version of a pre-alpha. You’ve been warned!

If this makes you queasy, there’s always the ‘explain’ command that can act as your cheat sheet without actually having grb run the commands on your behalf.

For the extra queasy, well you can find the commands very easily without running grb. Just point your favorite editor to lib/git_remote_branch.rb. All commands are there, at the beginning of the file.

For the brave, try it out and tell me what you think. Improvements, bug reports and contributions are all welcome.

And remember, in case of an emergency, you can always refer to my illustrated guide to recovering lost commits with Git ;-)

Here’s what’s to come:

  • lots of tests
  • a ‘remotize’ functionality (for existing local branches)
  • a much better resilience to use in faulty situations (e.g. deleting something that’s not present locally or remotely)
  • the possibility to specify different branch names locally vs remotely
  • slap an open source licence on it all
  • and so much more!

Posted in garbage out, git_remote_branch, programming | 12 Comments »