Every Flavour Beans

“The time has come…to talk of many [technologies].” –Lewis Carroll(‘The Walrus and the Carpenter’)
Development Tools. Web Frameworks. GNU/Linux. Nokia N800. Video Encoding.

December 9, 2008

Setting Up Ruby on Rails Projects with Git and Github

Filed under: General — tabrez @ 4:15 pm

Git is the favourite source code management tool of the Ruby on Rails community these days. Though GNU/Linux or Mac platforms are generally preferred to Windows by Ruby on Rails as well as git communities, I will show you how you can work with these technologies on Windows platform. I will also show how to host a git public/share repository of a Rails application on the Github free web service. Note that the following information applies to any project, not just Rails.

  1. Refer to my earlier post to see how to install Ruby on Rails on the Windows platform. You can skip some of the later parts if you wish.

    Setting Up Rails Development Environment on Windows Vista/XP

  2. Git still has some issues on the Windows platform but for normal usage the msysgit package shouldn’t let you down. Download and install it from its Google Code page.

    Download msysgit for Windows

    Read the information in last few dialog boxes carefully during the installation and select the settings you prefer. The following screenshots show the settings I have picked when installing msysgit on my system.

    Install a separate git shell in which to run the git commands:

    Git's independent command shell

    I can go to any git initialized directory, right-click a file and say “Git Bash Here” which will save me a lot of ‘cd’ commands:

    Start Git shell from any Windows directory

    Git’s built-in SSH support is more than enough for development purposes:

    Git's built-in SSH support

    Now you can just go to any Rails directory and run ‘git init’ there to track the files under git.

    Start Git Bash shell from the Start Menu.

    Go to your Rails directory and run the following commands.

    Example session:

    # cd hello
    # ls
    # git init
    # git add .

    For more git commands that you can use, refer to Git Tutorial. To learn more about how Git handles line ending conversions(especially important to Windows users), refer to gitattributes man page.

  3. If you are working alone on a particular application or you are just interested in maintaining the history of the source code changes locally, then you might prefer just working with in the project directory. If I want to share the changes with friends/colleagues or the world at large, we need a public git repository. Github and Assembla are but only two examples that have good free packages to get started with.

    Create a new account on Github.

    • Go to github.com
    • Click the link “Pricing and Signup” at the top of the page.
    • Pick a package(say “Open source” which is free) and click “Signup” button.
    • Fill in the information and click “I agree, sign me up!” button if you agree to all the policies.

    You need to enter your public SSH key when creating a Github account. If you don’t already have SSH keys generated, you can generate one using git tools. Github website has nice explanation on how to go about setting up SSH key on Windows for Github, so just follow the procedure.

    Once you have created the account and are logged in, click the “Create new one” link on the dashboard page, fill in the details and click the “Create Repository” button to create an empty repository on Github.

    Now you can push the contents of your Rails directory to the empty git repository that we created on Github in the previous step by running the following command in Git Bash shell:

    # cd hello
    # git remote add origin git@github.com:tabrez/hello.git
    # git push origin master

    Adjust the second command according to your account/project details. Now you can say ‘git push’ from your git tracked directory anytime you want to publish your changes to Github, so that others can pull these changes to their computers and merge them with their local git repository.

    Read more about git push.
    Read more about Github.

I will try to write about more tools that help in being more productive with development with Rails in future articles.


If you want to receive future posts by email, enter your email address here:

Related Posts:

  • Setting Up Rails Development Environment on Fedora GNU/Linux
  • Setting Up Rails Development Environment using Aptana Studio
  • “Hello, World” Web Application in Ruby on Rails using console
  • Setting Up Rails Development Environment on Ubuntu GNU/Linux
  • “Hello, World” Web Application in Ruby on Rails using Aptana Studio
  • Setting Up Rails Development Environment on Windows Vista/XP
  • Setting Up Development Environment For Grails on Windows Vista/XP


  • 3 Comments »

    1. Hi,

      Hope you are doing well. 9.9 media is starting a new initiative
      http://www.createonlinebuzz.com/ . If you are interested in making money
      through your blog by occasionally writing reviews of products and services
      please log onto http://www.createonlinebuzz.com/ and register as a
      blogger.

      Best Wishes
      S Malhotra

      Quote

      Comment by S Malhotra — December 23, 2008 @ 12:40 pm

    2. [...] http://github.com/guides/git-cheat-sheet http://github.com/guides/showing-and-tracking-remote-branches http://github.com/guides/push-a-branch-to-github http://github.com/guides/keeping-a-git-fork-in-sync-with-the-forked-repo http://beans.seartipy.com/2008/12/09/setting-up-ruby-on-rails-projects-with-git-and-github/ [...]

      Quote

      Pingback by Git/Github survival guide | Ivan Porto Carrero — March 21, 2009 @ 11:03 pm

    3. Thanks for the article! Got me up and running in no time flat

      Regards,
      Schalk Neethling
      OpenSource Release Feed

      Quote

      Comment by Schalk — August 9, 2009 @ 5:31 pm

    RSS feed for comments on this post. TrackBack URI

    Leave a comment


    Copyright (c) 2006, 2007 Tabrez Iqbal.
    Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. Verbatim copying and distribution of this entire article is permitted in any medium without royalty provided this notice is preserved. A copy of the license is included in the section entitled "GNU Free Documentation License".


    Powered by WordPress
    This website is hosted by Dreamhost