Showing posts with label Tools. Show all posts
Showing posts with label Tools. Show all posts

Thursday, February 03, 2011

Creating a locally tracked remote branch with Git

Updated May 30, 2013

Git is a distributed source code control system that allows you to clone a remote repository locally, make commits to it on your machine, and then push them to the remote repository when done.

It is often useful to create a remote branch for features that are experimental or will not be going out in the upcoming release as that allows you to work in isolation of the main code repository changes, thus not get blocked.

In order to work with a Git remote branch, it has to be cloned locally, and there are multiple ways of doing it with different levels of complexity. Some have you create the local branch first. Others have you create the remote branch first.

My intention for this blog post is to document the easiest way to date for creating a remote branch that is tracked locally.

Here it goes (assuming origin is the default):

git branch new_branch_name
git push -u origin new_branch_name


Then you can checkout the local branch and work with it by typing:

git checkout new_branch_name


The local branch automatically tracks the remote branch, so you do not have to worry about explicitly setting that up.

Now, if you already have a remote branch created by someone else though, and you want to check it out locally, you can just run this command (assuming remote is origin):
git checkout -t -b branch_name origin/branch_name

Update: A shorter alternative:

git checkout -t origin/branch_name


A Google search turns out a dozen ways, many of which are over-complicated or out-dated, so I hope people find this blog post helpful for providing the simplest approach to date.

Friday, April 16, 2010

Unproductive developer habits

Updated: May 13, 2010
Ever since I switched from Java to Ruby and Windows to Mac, leaving away the powerful IDE support I had in Java (Eclipse) and the mnemonic shortcut support I had in Windows, I have been dissatisfied with the level of flow I have while writing code.
With Eclipse on Windows, I had the option of soaring mouse-less, not wasting an ounce of brain power on the interruption of switching to the command line, taking my hand off the keyboard to control the mouse, or typing many characters to open a file when I could have done a quick project search with autocomplete and opened it in a breeze.
Unfortunately that is not the case on the Mac (no mnemonics) and many of the Ruby IDEs/Editors are unstable, require too much typing to perform common shortcuts, or simply miss many of the powerful navigation features I once had in Eclipse.
What disheartens me the most though is that a lot of developers that I meet have incredibly unproductive habits and they are quite oblivious to them. Here are some examples:
  • They use the mouse to do almost everything, including saving the file via a click on File and then Save (use the toolbar button at least!)
  • They have the mouse trackpad set to very slow making it further unproductive to use the mouse
  • Not knowing how to navigate or highlight with the arrow keys on the keyboard
  • Typing with two fingers only while looking at the keyboard
  • Navigating the folder structure with the mouse to open a file when they could have typed a few letters and relied on autocomplete to find it instantaneously
  • Not knowing about the jump to file shortcut for opening a highlighted class or method instantly
  • Switching tabs with the mouse instead of knowing the keyboard shortcut (CTRL+PGDN on Windows)
  • Doing find and replace with reliance on the mouse instead of a quick replace or replace all shortcut
  • Not knowing about alt mnemonics in Windows and Linux (Macs suck for not having that feature) and thus using the mouse for a lot of tasks that could have been performed with a few keyboard strokes
  • Moving files by typing extremely long commands on the command line to move a file when they could have benefited positively from the mouse for once to do quicker drag and drop
And these are just a few that I could think of right now.
Yes, I've tried the Eclipse Ruby plugin, Aptana RadRails, Sun NetBeans, and IntelliJ RubyMine. Each has its own pros and cons. None brings back the holy grail days of mouse-less Java development with Eclipse.
And, I am not talking about the loss of features that are achievable only with static typing. I am fine without those.What I am missing is just interruption-free navigation with the keyboard with as few strokes as possible.
What then? Write my own Ruby editor for the Mac? Write my own plugins for VIM? Both ideas seem worthy of consideration.
Further Comments (May 13, 2010):
Some people I talked to tried to simplify the interpretation of this blog post into blaming Ruby dynamic typing for not being productive (not true), IDEs for being bloated and making you use the mouse (not always true), or even the Mac not being shortcut friendly (not fully true either).
I would like to clarify that like any real situation no one thing is the sole factor to blame and none of it is black and white. This is about a combination of a lacking shortcut support in some editors/IDEs, lack of mnemonic support on the Mac (though compensating with great shell support), and lack of care about the situation by a lot of developers who are content to continue use the mouse or use inefficient shortcuts that require many keystrokes.
Also, I would like to clarify that despite all of this, I find myself much more productive in Ruby given how much less code I write (compensating for less productivity with certain things like massive refactorings). That was one of the biggest paradoxes that I encountered after I was half a dozen months down the road of programming in Ruby, which prevented me from switching back to Java. Of course, that is only given the fact that I am ruthless with test-driven development whether in Java or Ruby.
p.s. here is a blog post on useful Eclipse shortcuts for the curious:
p.s.2 2021-07-01: I did end up writing my own Ruby editor for the Mac and Windows/Linux too. It's called Gladiator (Glimmer Editor). I work in it completely mouse-less for the most part, and am very satisfied with productivity in it. 

Tuesday, June 02, 2009

The IDE vs Editor War in the Ruby World

Ever since I switched to Ruby programming last September to develop Rails web applications, I've been fighting an up-hill battle to convince other developers of the value of using Eclipse or IDEs in general.

Since Ruby is an interpreted language (with a transparent compilation step for optimizations purposes only), developers mainly rely on test-driven development to produce reliable code. Auto-compilation and verification of code is thus rendered for the most part unnecessary.

Additionally, given Ruby's support for attributes (via attr* methods) and no need to declare class variables, many of the source code generators used in Java are not needed in Ruby. After all, Ruby's philosophy is about producting the tersest most abstract code, free of boiler-plate repetitive code.

Refactoring with Ruby is often done manually, but given that there isn't usually a lot of code with proper abstraction, and given Ruby's method aliasing support, huge refactorings of the nature that ripples through the whole system are rare, and thus refactoring is quite easy to perform manually especially given the protection of the Ruby must-have unit tests.

So, what does that leave as far as tooling needs? Color coding, syntax highlighting, file lookup, search and replace, and possibly some autocompletion capabilities.

Well, these limited needs brought back the popularity of simple editors that support just these features. By simple editors, I do actually mean good old VIM and emacs as well as the new extremely popular Mac editor, TextMate.

After 10 months of pair-programming with different Ruby developers with varying habits and backgrounds, I got to do a pilgrimage through most Ruby editors and IDEs. So far, I've gone through TextMate, VIM, Aptana RadRails, Eclipse DLTK, NetBeans, and IntelliJ RubyMine.

Yes, I'm a shortcut freak, and I used to write Java programs in Eclipse mouse-less!!! So, how did other editors and IDEs measure in comparison as far as shortcuts and productivity?

I'll leave that to another post.

In the meantime, what is your opinion of the matter? Do any of you prefer editors over IDEs? If so what's your editor/IDE of choice and what are the reasons you like it? Feel free to mention different ones for different programming languages.