Using Git is one of those things I’ve been postponing for ages. At 40Fingers (and pretty much all other projects I’m involved in) we’re using SVN as our versioning system. I know how it works, it does what I need it to do, so why bother? Well, because everybody around me seems to be leaving SVN for Git and they can’t ALL be wrong, right?
Anyway, there’s probably plenty of other content out there about why you should or shouldn't use either one. I decided I need to, so here goes…
Since I’m one of the developers for NB_Store, which is an open source e-commerce module for DotNetNuke, I fixed a bug in it. While I could of course commit the fix straight into the main development branch (or the master for that matter), for this blogpost, I’ll do it using a pull request.
Step 0: install TortoiseGit
Since I haven’t done much with Git at all, I don’t know much about what Git client would be the best. I’m pretty happy with TortoiseSVN, so I figured I’d give TortoiseGit a shot. Get it here: http://code.google.com/p/tortoisegit/
Step 1: Create a fork
So, what do we need a fork for? Well, It allows me to have my own copy of the NB_Store sources on Codeplex. I can keep it in Sync with the official project, create my own branches for development and send pull requests to the main project when I’m happy with something.
So, off we go, to then NB_Store project on CodePlex, log in and navigate straight to the Source Code tab. Things might look a little difference at your end, because I happen to be a coordinator on the project:
I’m going to fork the current master branch. So I have “master” selected and click the Fork link and click “Create new fork” in the popup panel:
Since this will be my own nb_store development fork, not for one specific feature, I’ll just name it “nbstore”
and click Save on the form that appears:
Now, you see there’s an extra fork on the NB_Store master branch:
Step 2: Clone the fork
The fork as “in the cloud” on CodePlex. I can’t work on that, I need to have the code locally on my machine, of course.
So, to create my clone, I’m going to open DNN’s DesktopModules folder in Windows Explorer, right click and choose “Git Clone…”:
I’m creating a clone right from my CodePlex fork into my working folder:
Clicking OK initiates the Download of all files to my pc.
At this point, there are 3 repositories of NB_Store I’m working with:
- the upstream repository: the main NB_Store repository on CodePlex
- the origin repository: my own fork of NB_Store, also on CodePlex
- the local repository in the DesktopModules folder on my own machine
Step 3: Branch
Now, while I could open the project now and start working, it’s advisable to create a so-called feature branch first. That will keep my fork nice and clean over time. It will also make it a lot easier to create single-feature pull requests.
I need to fix an issue related to all-lowercase-url’s for NB_Store’s back office module. If you’re not all that familiar with NB_Store: forget it. I just mean I need to make a feature-branch and name it something that makes sense. So, right-click my local repository folder, select TortoiseGit submenu and select Create Branch:
Notice that I’m switching to the new branch right away.
Step 4: Make that change
I’m not going to cover that here: I’m making the change I need to make in the code. In this case it’s only a few lines in a single file.
Step 5: Commit the change
Now that I’ve made my change, I’ll need to get it stored on CodePlex. To get that done, I use the TortoiseGit context menu again and choose the quick Git Commit option:
Next, I’ll enter a commit message and click OK. The next dialog allow me to push my changes to my origin right away:
I will need to enter the remote branch name here too, and click OK. You might be asked for your CodePlex credentials at this point:
Now, when I go back to NB_Store on CodePlex and select my fork, I will see my own feature branch in the dropdown, and when I select it, I’ll see my commit:
Step 6: Create a Pull Request
Finally, I want to send my changes to the development team to allow them to review it and merge the changes in some release if they choose to. This is all done on CodePlex itself. Click the link “Send pull request” in the above screenshot:
Make sure you’re sending a pull request from the right branch (I chose my new feature branch and the upstream master). Then fill out the little form with some handy information and click send:
I know this helped me understand Git a bit better, so if you want to give it a shot yourself, just go ahead and give it try!