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.

 

Diskutera uppgift


  • trycatchblock sa:

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

    https://github.com/dublinan/coursework

    leads to a 404. What happened here?

    i 18 maj 2013 12:57

    sad_tigger sa:

    i 18 maj 2013 14:15 som svar på trycatchblock

    Andre Dublin sa:

    sorry about that I updated the link

    i 19 maj 2013 22:45 som svar på trycatchblock
  • ivorsmashman sa:

    Installed on Fedora 18, from the repos, because I'm lazy.
    i 25 januari 2013 18:12
  • Jure sa:

    Installed Windows gitHub

    i 29 oktober 2012 08:13
  • David O'Dowd sa:

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

    i 29 september 2012 22:05

    Andre Dublin sa:

    Right on track David

    i 29 september 2012 22:33 som svar på David O'Dowd

    David O'Dowd sa:

    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.

    i 30 september 2012 07:21 som svar på Andre Dublin

    Andre Dublin sa:

    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.

    i 30 september 2012 20:15 som svar på David O'Dowd
  • RobRoy sa:

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

    i 10 september 2012 18:38

    Andre Dublin sa:

    What do you need assistance with?

    i 11 september 2012 07:13 som svar på RobRoy

    Georgiy Slobodenyuk sa:

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

    i 11 september 2012 12:47 som svar på RobRoy

    RobRoy sa:

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

    i 11 september 2012 12:58 som svar på Georgiy Slobodenyuk
  • Shubham sa:

    i 19 augusti 2012 01:21

    narendhar sa:

    congrats..

    i 19 augusti 2012 02:56 som svar på Shubham

    Andre Dublin sa:

    Excellent

    i 19 augusti 2012 20:40 som svar på Shubham
  • narendhar sa:

    Created my git account 

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

    i 17 augusti 2012 09:40

    Andre Dublin sa:

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

    i 17 augusti 2012 09:42 som svar på narendhar

    narendhar sa:

    Hai,

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

    i 17 augusti 2012 10:16 som svar på Andre Dublin

    Andre Dublin sa:

    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.

    i 17 augusti 2012 10:23 som svar på narendhar
  • Frank Murphy sa:

    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

    i 1 april 2012 07:03

    Andre Dublin sa:

    can you provide a link to your git account

    i 1 april 2012 09:42 som svar på Frank Murphy

    Frank Murphy sa:

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

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

    i 1 april 2012 09:54 som svar på Andre Dublin

    Andre Dublin sa:

    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.

    i 1 april 2012 11:16 som svar på Frank Murphy
  • Anonym sa:

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

    i 12 mars 2012 00:52
  • Peter Hwang sa:

    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

    i 11 mars 2012 13:35

    Rhodee sa:

    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

    i 11 mars 2012 14:14 som svar på Peter Hwang

    Peter Hwang sa:

    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

    i 11 mars 2012 17:16 som svar på Rhodee

    Andre Dublin sa:

    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.

    i 11 mars 2012 18:02 som svar på Peter Hwang

    Peter Hwang sa:

    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

    i 11 mars 2012 18:11 som svar på Andre Dublin

    Andre Dublin sa:

    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.

    i 11 mars 2012 19:35 som svar på Peter Hwang

    Peter Hwang sa:

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

    i 11 mars 2012 20:41 som svar på Andre Dublin

    Rhodee sa:

    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!

    i 11 mars 2012 21:14 som svar på Peter Hwang

    Anonym sa:

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

    i 12 mars 2012 00:54 som svar på Peter Hwang

    Andre Dublin sa:

    Hey Peter,

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

    I'm hunting an answer for you.

    i 12 mars 2012 12:22 som svar på Peter Hwang

    Peter Hwang sa:

    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.

    i 12 mars 2012 12:32 som svar på Andre Dublin

    Andre Dublin sa:

    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

    i 12 mars 2012 12:44 som svar på Peter Hwang

    Peter Hwang sa:

    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!

     

    i 12 mars 2012 14:29 som svar på Andre Dublin

    Andre Dublin sa:

    Excellent

    i 12 mars 2012 14:50 som svar på Peter Hwang
  • Andre Dublin sa:

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

    i 9 mars 2012 22:25
  • Mark Finlay sa:

    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.

    i 9 mars 2012 19:43

    Mark Finlay sa:

    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.

    i 16 mars 2012 20:18 som svar på Mark Finlay

    Andre Dublin sa:

    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

    i 16 mars 2012 22:37 som svar på Mark Finlay