yeomanly

Setting Up a Riaforge Project with Git and GitHub (Part 3)

2009 October 20
by Mike Henke

This is a 4 part series over Git and GitHub with Riaforge. So far we installed some software, registered for a free GitHub account, created a repository, and cloned it.

Lets demonstrate the power of GitHub, anyone can make contributes to a project on GitHub. We will be using CWheels on GitHub to create a fork and send a pull request of our changes to CFWheels.

Forking Bad, Think Again

Forking? You may thing forking is bad. Recently, CFHour() podcast even mentioned that forking isn't good but they are wrong. They are likely using a source control system that makes branching and forking difficult. Forking in git is encouraged. Git makes it easy to merge forks whenever.

Forking made easy

Log into GitHub with your username and password, then go to CFWheels on GitHub (http://github.com/rip747/CFWheels). You will notice this page is slightly different then the repository home page we created. This has only a public clone url and a fork button. Click on that fork button.

In a couple seconds, you should have your own CFWheels fork. When completed, notice CFWheels is now under your name (my example is http://github.com/mhenke/CFWheels) Copy your new clone url. Mine is git@github.com:mhenke/cfwheels.git, yours should be similar.

Set Up

We will start with a fresh local ColdFusion multi server instance to place the code in. Also please have everything working from the previous posts.

Cloning our CFWheels Fork

We cloned a newly create GitHub repository through the command prompt in the last post but we also installed two other git clients. One integrating with Eclipse, eGit, and the other with Windows Explorer, TortoiseGit (TG).

Navigate to your webroot (mine is C:\JRun4\servers\CFWheels\cfusion.ear\cfusion.war ) and right click on the folder or inside the folder to create the git repository. This screenshot is the former and shows how TG is integrated into Windows Explorer. Select "Git Create repository here"



As you have noticed, a folder called .git has been created. If using the command prompt, we would have navigated into the folder and run "git init".

Adding A Remote

Now we will tell this git instance about our CFWheels fork on GitHub by adding a remote reference. If using the command prompt, we would run "git remote add origin git://git@github.com:mhenke/cfwheels.git" within our webroot. Using TG, right click in the webroot, select TortoiseGit —> Settings.



Then in the dialog box, select Remote under Git, press "Add New", and paste in our CFWheels fork url we copied previously, click "Apply", then "Ok".

Fetching our CFWheels Fork

Now we will do a fetch. Git has three commands dealing with remote repositories. Push and Fetch are opposites and do what the sound like. Pull actually does a Fetch plus a merge. Committing is only to our local repository.

Right-click in the webroot and select Fetch. A dialog box should appear and select OK.



We could have created our remote with the "Manage Remotes" on the fetch dialog box. Close the Git Command Progress dialog window, but notice the git command for the command prompt. TG actually created two branches also.



You may be disappointed when you check the webroot since no files were created. We actually have to tell git what branch to switch/checkout. Right click in our webroot folder and select TortoiseGit —> Switch/Checkout.



Make sure to use the master branch and press Ok. Now we have files to work with.

Setting up eGit

We have to create a symbolic link used by eGit to .ssh called ssh. If you are using Vista, open the command prompt and navigate to the folder containing the .ssh folder you created in Part 2 (mine is "C:\Users\Owner"). Run this command "mklink /D ssh .ssh". If you are using XP, download this program "Junction Link Magic 1.0" and create a link to .ssh from ssh.

Setting up a global ignore

Let's add an global ignore file before making changes. I placed mine in C:\JRun4\servers . In the command prompt, navigate to our CFWheels webroot with the git repository. Run "git status". Notice the untracked files, these are files we don't want to add to the repository and aren't staged yet. Any changes need to be staged to be committed. This is different from SVN since if we modify a file and commit it would get commit to the SVN repository. Git has an extra space called stage. This is nice if we want to customize our commit.

My .gitignore files contains this:

# Ignore these folders and sub content
CFIDE/*

META-INF/*

WEB-INF/*



# Ignore all dotfiles…
.*

# except for .gitignore
!.gitignore

/.*/*


So let's add the global exclude file by running git config —global core.excludesfile "C:\JRun4\servers.gitignore". In the command prompt, do another "git status", notice only one file is shown as untracked. If we wanted to commit that file, we would "git add settings.xml" and it would be tracked but still not staged.

Make an Awesome Contribution

With that done, open Eclipse, create a project to our CFWheels webroot. Then right-click on the project and select Team —> Share Project. In the Share Project dialog box, select Git, then our CFWheel repository, and click Finish. You can now make commits to our local repository by right clicking on the project folder, selecting Team, then Commit. When we want to push to our remote repository on GitHub, right click on the project folder, select Team, then Push To.

Push To Walkthrough



Select Next and Yes a couple times on the SS2 Messages. Usually, I push "Add all bracnhes spec" but some reason, it didn't work this time so I selected items from source ref and destination ref, clicked add spec. and then Finish.



I am going to wrap this post up. You can see my awesome contribute here http://github.com/mhenke/cfwheels/commits/master. Next I would click on the pull request button on my CFWheels fork page to notify CFWheels about the changes.

Screencasts and Videos to Watch


Getting started with GitHub (Teach Me To Code)

GitCasts

Insider Guide to GitHub screencasts with Scott Chacon

Setting Up a Riaforge Project with Git and GitHub (Part 3)

10 Responses leave one →
  1. tony petruzzi
    Oct 21, 2009 at 12:41 PM

    absolutely awesome mike!!!

  1. Mike Henke
    Oct 21, 2009 at 5:08 PM

    Hopefully you are talking about the post and not my awesome contribution :-)

  1. sameer
    Oct 22, 2009 at 4:26 AM

    hello, thank you for all the three articles. you made me understand what github is. but SVN thing is working so fine, why switch to github? actually, i am not sure who needs another version management.

  1. Mike Henke
    Oct 22, 2009 at 6:45 AM

    I think you meant why switch to git. http://whygitisbetterthanx.com/

  1. sameer
    Oct 22, 2009 at 7:14 AM

    Thanks for sharing that URL. Tough, I want to point out that its completely biased towards github. SVN too offers local repository and in most cases git is not compared with SVN. As far as I know, SVN is a time tested solution.

    Github is promoting its services. I can offer similar features with just SVN and CF. But check this site out: http://svnhub.com/ ;)

    if someone needs to host a large project on github.com, you have to pay for that. while svn @ google code is entirely free. some people still use CVS @ sourceforge.net but its a solid foundation.

  1. Mike Henke
    Oct 22, 2009 at 10:05 AM

    That is funny, I just read an article and the comment was CVS was fine and time-tested but SVN isn't :-)

    For any SVN hosting site, nobody can make contributes without being granted rights to the code base (you could email your code but if the owners don't add it, other people can't use your contribute). With GitHub, anyone can fork and contribute. If the contribution isn't added to the original, people could still use your code contribute.

    I am not sure we on the same page for "local" repositories.

    SVN has a central repository, it could be anywhere but it is central. You check out code into a working spaces but not the repos. The repos is not "local".

    Git has a distributed repos, the repos and the code is cloned.

    Here is a comparison of SVN and Git http://bit.ly/wBScR

    Thanks for the comments, this is making me research more :-)

  1. sameer
    Oct 22, 2009 at 11:31 AM

    I agree that there is forking benefit of using git.

    I have used and installed svn extensively and understand that SVN and CVS are already what SCM could be. In Git terminology you will Fork, the same would be called Branching in SVN terminology. Its an issue that you are "not authorized" to create "Branch" of a project, but developers at Google Code can grant such permission to public (push-button-branching) with few lines of code: "svn copy" and grant your gmail id access to specific branch only.

    Distributed repos are available in SVN too. Use the command line svnsync. In its current version 1.5 & 1.6 it helps multiples offices work on a project locally and sync to master.

    Github is "yet another SCM" for people to add to their résumé. Cool, its a (yet another) social network. As mentioned above, if you wish to clone an existing project and jump start, sure go for it. In other situations and in our offices and in your projects SVN is suffice - we can create a branch (fork) for intrested people and assign specific rights with SVN today.

    CVS was introduced in 1990s and no doubt is rock solid. SVN started in year 2000, but brought http repos browsing and hence is heavely successful. While git started just 3/or 4 years back. SVN is still improving with each passing day and studies also suggest that its the best SCM. You know companies like Google who use SVN will develop something on their own if it wasn't so good. Read about few actual svn issues and cool facts about svn: http://en.wikipedia.org/wiki/Subversion_(software)

  1. tony petruzzi
    Oct 22, 2009 at 2:06 PM

    @sameer

    as far as i know, the biggest draw back to working with svn is not being able to commit your changes except to the master repo, which doesn't work for me when i'm working on wheels. with every feature or bug fix i'm working on, i create a new branch in git and i'm able to commit and go nut with. once i'm done, i merge with the wheels master locally and git svn rebase to the google code repo.

    the other thing i absolutely cannot stand about svn is committing changes itself. git allows me to commit whole files or portions of a file. with svn it's the whole file or nothing which sometime does work.

    also with git i can do 15 commits and then rebase and squash them down to 5 commits if i want before pushing my changes. the only way to do something like that with svn is reverse merging which is horrible.

    for some people though, svn will work just nicely and maybe they don't need nor want the power that git provides, at least they're using some sort of scm. me personally i like being to use all the cool things that git provides to keep me working offline and my commits organized.

  1. Mike Henke
    Oct 22, 2009 at 7:06 PM

    Is branching and merging easy in SVN? I am a big source control advocate, I have implemented SVN at a former job and used it prior but SVN branching and merging back was pain. Branching and merging in Git is front and center, everything is a branch.

    svnsync is read only repos mirrors replaying commits. SVN isn't a distributed source control system, no matter many tools are added to give it that feel.

    Forking on Google Code (or any other SVN hosting) - http://bit.ly/2dFGLP

  1. Mike Henke
    Oct 23, 2009 at 1:10 PM

    Here are the git commands from the command prompt for creating git in an existing directory.

    git init
    git remote add origin remote_machine:~brentg/my_setup.git
    git fetch
    git branch master origin/master
    git checkout master

Leave a Reply

Leave this field empty: