This course will become read-only in the near future. Tell us at community.p2pu.org if that is a problem.

Setting up Git and using Github


Clone, commit, push, pull, rinse and repeat!

 

For this course, GitHub is used as a central repository for exercise submissions. Each course participant will create an account on GitHub, fork (i.e., copy) the course repository, modify the skeleton files to complete assignments, and push the completed work back up to GitHub for all to see and review.

Installing Git

git is a distributed version control system. Version control systems are an important toolkit in a developer's arsenal: they allow developers to track changes to their code over time and operate well in a team. Developers usually commit small changes as they complete features, creating revisions that are archived and never lost.

git is the most popular version control system used with Ruby at this time.

git does not have the gentlest learning curve, but the basic functions are pretty straightforward and well documented.

Reading Assignment: Learn more about git by reading Pro Git - Git Basics.

Task: Sign up for a free account on GitHub.

Reading Assignment: After you've learned about git at a high level, setup git on your local machine by following the instructions on GitHub for your platform. Follow the entire guide, including setting up SSH keys.

Alternatives to installing GIt:

Its great that technology makes life eaiser for us, but its better to know how the internals of a system works.  For those less adventurous here are some other ways of interacting with git and github.

Windows: http://windows.github.com/

Mac: http://mac.github.com/

Forking the Course Repository

Reading Assignment: Read the GitHub guide to forking a repository.

Task: Fork the coursework repository. Specifically, follow along with this screencast.

 

Task Discussion


  • trycatchblock said:

    https://github.com/p2pu-intro-ruby/coursework

    https://github.com/dublinan/coursework

    leads to a 404. What happened here?

    on May 18, 2013, 12:57 p.m.

    sad_tigger said:

    on May 18, 2013, 2:15 p.m. in reply to trycatchblock

    Andre Dublin said:

    sorry about that I updated the link

    on May 19, 2013, 10:45 p.m. in reply to trycatchblock
  • __hsams__ said:

    Installed on Fedora 18, from the repos, because I'm lazy.
    on Jan. 25, 2013, 6:12 p.m.
  • Jure said:

    Installed Windows gitHub

    on Oct. 29, 2012, 8:13 a.m.
  • David O'Dowd said:

    I'm hoping I have done this all correctly. https://github.com/davidodowd/coursework

    on Sept. 29, 2012, 10:05 p.m.

    Andre Dublin said:

    Right on track David

    on Sept. 29, 2012, 10:33 p.m. in reply to David O'Dowd

    David O'Dowd said:

    Thanks Andre. It might be worth adding steps about what http://windows.github.com/ does. Should people be using it or should they be learning by using the commands.

    on Sept. 30, 2012, 7:21 a.m. in reply to Andre Dublin

    Andre Dublin said:

    I'd like the course to introduce people to the command line, since ruby and rails both use it heavily.  Also being comfortable in the command line gives people confidence in other areas of software development.

    Thanks, I'll add it to the course materials.

    on Sept. 30, 2012, 8:15 p.m. in reply to David O'Dowd
  • RobRoy said:

    I found dublinan/coursework repository empty. I don't get it. 

    on Sept. 10, 2012, 6:38 p.m.

    Andre Dublin said:

    What do you need assistance with?

    on Sept. 11, 2012, 7:13 a.m. in reply to RobRoy

    Georgiy Slobodenyuk said:

    It should only have a README file. It is meant to be copied and modified. 

    on Sept. 11, 2012, 12:47 p.m. in reply to RobRoy

    RobRoy said:

    OK. I thought I find in the repository partly prepared exercises. Now I understand, I need to write them and then put into repository.

    on Sept. 11, 2012, 12:58 p.m. in reply to Georgiy Slobodenyuk
  • Shubham said:

    on Aug. 19, 2012, 1:21 a.m.

    narendhar said:

    congrats..

    on Aug. 19, 2012, 2:56 a.m. in reply to Shubham

    Andre Dublin said:

    Excellent

    on Aug. 19, 2012, 8:40 p.m. in reply to Shubham
  • narendhar said:

    Created my git account 

     https://github.com/narendahr15/Spoon-Knife

    on Aug. 17, 2012, 9:40 a.m.

    Andre Dublin said:

    Looks good, if your using your own repo for the course that is fine smiley

    on Aug. 17, 2012, 9:42 a.m. in reply to narendhar

    narendhar said:

    Hai,

        I am a novice in this field.What is use of these repo in ruby?

    on Aug. 17, 2012, 10:16 a.m. in reply to Andre Dublin

    Andre Dublin said:

    I'm just having you all as students understand some basic git commands with this challenge, and understand basic parts of github.

    The use of github repos will allow me to read over your work and provide help where needed.  If that answers your question.

    on Aug. 17, 2012, 10:23 a.m. in reply to narendhar
  • Frank Murphy said:

    Ok, getting some time fianlly.

    Git account setup.

    One error on:

    git remote add upstream git://github.com/octocat/LearnRuby.git
     

     git fetch upstream

    fatal: The remote end hung up unexpectedly

    on April 1, 2012, 7:03 a.m.

    Andre Dublin said:

    can you provide a link to your git account

    on April 1, 2012, 9:42 a.m. in reply to Frank Murphy

    Frank Murphy said:

    https://Frankly3D@github.com/Frankly3D/LearnRuby.git

    git://github.com/Frankly3D/LearnRuby.git

    on April 1, 2012, 9:54 a.m. in reply to Andre Dublin

    Andre Dublin said:

    Ok, here is how you will copy your repo localy

    $ git clone git@github.com:Frankly3D/LearnRuby.git

     

    You won't have to set up a remote because cloning, automatically creates it.  Then all you have to do is follow this workflow

    $ git add <fllename>

    or

    $ git add .

    . is all files that have been changed/added to the repo

    $ git commit -m "your message here"
    
    $ git push origin master

     

    You won't have to worry about using upstream, upstream is used when say your working from two different machines, or you have collaboraters on a project and there are changes to the remote repo git fetch upstream will pull in those changes for you without merging.

    on April 1, 2012, 11:16 a.m. in reply to Frank Murphy
  • Anonym said:

    All steps went ok, git account is set up. I followed the github page tutorial. (mac lion) 

    on March 12, 2012, 12:52 a.m.
  • Peter Hwang said:

    I'm having some problems cloning.  See below.  Any ideas on what I'm doing wrong?

     

    Peters-MacBook-Air:~ hwangpet$ git clone git@github.com:hwangpet/coursework.git
    Cloning into 'coursework'...
    error: cannot run ssh: No such file or directory
    fatal: unable to fork

    on March 11, 2012, 1:35 p.m.

    Rhodee said:

    The error seems to be telling you that github can't find your public keys:

     

    So try this: http://help.github.com/mac-set-up-git/

     

    If this is the only identity you have (i.e. only one github account) you can simply follow  along. If you have something more involved we might need to talk about your ssh setup.

     

    Shoot a message when you have worked through those steps (you only have to do it once)...unless this happens again.

    Denis

    on March 11, 2012, 2:14 p.m. in reply to Peter Hwang

    Peter Hwang said:

    Thanks.  Now I'm stuck on step 3.

     

    Peters-MacBook-Air:.ssh hwangpet$ ssh-keygen -t rsa -C "hwangpet@gmail.com"
    -bash: ssh-keygen: command not found

    on March 11, 2012, 5:16 p.m. in reply to Rhodee

    Andre Dublin said:

    Did you run this command at your prompt?

    ssh-keygen -t rsa -C "your_email@youremail.com"

    Just want to make sure your didn't put any extra words/characters in there

     

    Also it seems your running Lion OS X

    run echo $PATH in terminal and let me know the response.

    on March 11, 2012, 6:02 p.m. in reply to Peter Hwang

    Peter Hwang said:

    Andre,

    Thanks for reply.   See below:

     

    Peters-MacBook-Air:.ssh hwangpet$ ssh-keygen -t rsa -C "hwangpet@gmail.com"
    -bash: ssh-keygen: command not found


    Peters-MacBook-Air:.ssh hwangpet$ echo $PATH
    /usr/local/git/bin:/bin:/usr/local/bin:/bin:/usr/local/bin

    on March 11, 2012, 6:11 p.m. in reply to Andre Dublin

    Andre Dublin said:

    I think that you may have to install Xcode to obtain developer tools such as ssh.  Or you can roll your own and install openssh. However I recommend install Xcode.

    on March 11, 2012, 7:35 p.m. in reply to Peter Hwang

    Peter Hwang said:

    Installed xcode - still get the same errors.  Any other ideas?

    on March 11, 2012, 8:41 p.m. in reply to Andre Dublin

    Rhodee said:

    Hi Peter,

    Did you install xCode 4? I am not a Mac user, but this thread seems to be relevant: http://stackoverflow.com/questions/5364340/does-xcode-4-install-git.

     

    Perhaps since xCode appears to install git it simply can't find the path you can tell it to like this post suggest: http://stackoverflow.com/questions/5545715/how-do-i-add-usr-local-git-bin-to-the-path-on-mac-osx

     

    Keep plugging away man!

    on March 11, 2012, 9:14 p.m. in reply to Peter Hwang

    Anonym said:

    Peter, check it: http://bit.ly/zyDoRQ It may help with the ssh problem

    on March 12, 2012, 12:54 a.m. in reply to Peter Hwang

    Andre Dublin said:

    Hey Peter,

    Can you echo your $PATH again now that Xcode is installed?

    I'm hunting an answer for you.

    on March 12, 2012, 12:22 p.m. in reply to Peter Hwang

    Peter Hwang said:

    Andre,

    Here the result after running echo $PATH in terminal:

    wifi-dhcp-55-168:~ hwangpet$ echo $PATH
    /usr/local/git/bin

     

    Thanks again for all the help fellas!  I'm going to work with one of my developers today who already use github so hopefully they can point me in the right direction.

    on March 12, 2012, 12:32 p.m. in reply to Andre Dublin

    Andre Dublin said:

    It looks like your missing some necessary binarys in your PATH variable

    these basic path settings should be in your .bash_profile like so

    export PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:$PATH

    Not sure where your Xcode is, but your developers should understand the situation

    on March 12, 2012, 12:44 p.m. in reply to Peter Hwang

    Peter Hwang said:

    Andre - you were correct.  My .bash_profile was corrupted.  My echo $PATH looks normal now:

    wifi-dhcp-55-168:Users hwangpet$ echo $PATH
    /usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:/usr/local/git/bin:/usr/local/git/bin

    Thanks alot everyone!

     

    on March 12, 2012, 2:29 p.m. in reply to Andre Dublin

    Andre Dublin said:

    Excellent

    on March 12, 2012, 2:50 p.m. in reply to Peter Hwang
  • Andre Dublin said:

    I think you might be right about requiring git before you install rvm, but i believe you usually use curl to install...

    on March 9, 2012, 10:25 p.m.
  • Mark Finlay said:

    This one is a bit tricky with all the diferent steps between installing git, setting up the account and the ssh keys so that the installed Git on your machine can talk to your Github account.

    From what I can remember, to install RVM it also requires you to have Git installed on your machine for some reason. This might help poeple having trouble installing RVM.

    on March 9, 2012, 7:43 p.m.

    Mark Finlay said:

    Hey guys,

    I'm glad Peter is up and running. I remember having allot of the same issues trying to the different bits a pieces put together myself. I see that Peter has in his bash_profile:

    /usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:/usr/local/git/bin:/usr/local/git/bin

    I was wondering how does this actaully work? My understanding so far is that when you call a program to perform an action in the command line, for example "rails server", "mysql -u root" or "git init", the comand line looks for the named program in the directories mentioned in the bash_profile file. Am I right? Could someone clarify?

    Again, another aussumption is that, for programs to talk to each other on a host they need to know where each other exist on the hard disk. If I have a rails app that needs to resize an image, how does the rails app know where ImageMagick is? Do the diferent applications use the bash_profile as a directory to find each other?

    Also, How does the syntax of the bash_profile files or shell script work interms of tying libraries and applications together?

    Where does RubyGems and Bundler fit into this whole thing?

    Obviously this kind of stuff plays an important part in your development enviornment but it's plays a massive role in delievering code. Interms of depoying ruby applications to the web it's important to have a solid handle on how to setup Linux boxes. It would be great to get pointers to goood resourses on more learning for this kind of stuff.

    on March 16, 2012, 8:18 p.m. in reply to Mark Finlay

    Andre Dublin said:

    Hey Mark, excellent question!

    The string you see when you use echo $PATH in terminal is a result of a UNIX variable.  It tells terminal where to find the binarys necessary to execute programs the " : " is a delimiter that lets you specify multiple paths to where your binaries are located in the file system.

    How Ruby knows where to find stuff because when ruby is built for your particular machine, it has predefined directories to hold libraries.  Where these reside all depends on the machine you are using. So an Ubuntu OS Ruby location may be different from a Windows OS Ruby location, or when you install RVM the Ruby location is different and so on.

    If you run this command in terminal

    ruby -e 'puts $:'

    You will receive an output of the directories that Ruby is using.

    $: is a Ruby array variable of places to search for loaded files.

    As for Rubygems, it is a standardized packging and installation framework for Ruby libraries and apps.  Thus making it easier to install, upgrade, and locate Ruby packages.  Keeping lots of Ruby developers including myself sane.

    Rubygems handles all the dependencies, and version control of gems to install on your system.

    Bundler is sort of an extension for Rubygems in Ruby applications, using Gemfiles to install and locate gems necessary for your application.

    I hope this answers your question, here are some links below to help you further understand.

    The PATH Variable in UNIX

    Bundler

    Rubygems

    on March 16, 2012, 10:37 p.m. in reply to Mark Finlay