Posts tagged Source Control

Git –newbie –workflow

1

Introduction

I recently found the time to dedicate to learning a distributed version control system. I had the choice between Mercurial and Git. Both are great systems but what it came down to ultimately was the fact that I already had TortoiseGit on my machine. Yes you read that right, it came down to the fact that I didn’t want another source control provider taking up space in my context menu; frankly my context menu is getting a little ridiculous.my context menu I know it isn’t exactly a scientific method of picking between the two, but honestly, I see very little that is different between the two (for a learner).

Initial Reaction

When I first read the description of Git, I thought “who would be stupid enough to have source control on their own machine?” The second thought to go through my SVN-centric brain “I like SVN, so why should I change to Git?” The first question came out of ignorance to the ideas behind a distributed source control system, the second is a completely valid rebuttal.

I will attempt to address the first question. Yes your source control is on your machine but think of it as your own personal local copy of the “Truth.” You edit your version of the “Truth” until you feel comfortable with your additions and changes. The next step is to push your changes to a central version, possibly on GitHub or Unfuddle. That last step is important, because your source is no longer local. Your code now exists somewhere that is hopefully safe, secure, and accessible to you and your team of developers. What is powerful about Git is the fact that most of the expensive actions performed locally: commits, merges, additions, and deletions. This makes Git crazy fast, CRAAAAZZZY FAST! The two most expensive actions are pull and push, but even these can be quick if your central source control repository is on the local network. After a couple hours playing with Git, my ignorance about the ideas behind this system were overcome by an understanding and comfort.

The second question is valid. If you like SVN, why should you switch? Well nobody is forcing you to switch, and people won’t call you a loser if you decide to stick with SVN. I still have a warm place in my heart for SVN, it was the Han Solo of my escape from the Death Star known as VSS (Visual Source Safe). That being said, Git is a lot easier when it comes to branching and merging. In SVN branching occurs remotely on the SVN repository, which can be slow. In Git, branching happens locally and is even encouraged by most resources that I read. The one thing developers might gripe about Git is the fact that there really isn’t much Visual Studio integration. SVN has a ton of integration tools inside Visual Studio. What I would say about this though, is that the projects I work on have more than enough files outside of my VS Solution to negate the good aspects of integration tools. File types like third party assemblies, documentation, build scripts, and other files all exist outside the scope of my solutions. Now to add them to your SVN repository you are forced to use TortoiseSVN, a tool that exists outside Visual Studio.

I may or may not have convinced you to try Git, but I really feel you should. More and more compelling projects are being hosted on GitHub. How will you get involved and help these projects grow with a knowledge of Git? Also, Codeplex now offers Mercurial support, so don’t be suprised when your favorite projects on Codeplex start moving to a distrubuted SCM.

Basic Workflow

To get started with Git download MsysGit. This will setup an environment ready for Git on your windows machine.

I also recommend TekPub, they have a great series about mastering Git.

To learn about a system you have to use it, and that is what I did with Git. I wouldn’t call myself an expert but I do feel comfortable enough with it now to jump into a Git project. The basic Git workflow is as follows (type: “git help” in a command window):

  1. init or clone: if you are starting a repository use init, if you are getting use clone.
  2. branch: create a new branch to start working in or just work in the master branch.
  3. add: add any or all files involved in your project.
  4. commit: commit staged files to your local source repository.
  5. pull: get any changes that have occurred at the central repository.
  6. merge or rebase: make sure all your changes and branches are reflected in the master if need be.
  7. patch or push: some repositories online are private so you can produce a patch to send to the owners, if you own the repository the push away.
  8. Rinse and Repeat until content.

These are the commands you’ll need to know to just get by, but there are many more to become a master. I modified my environment to work with WinMerge for both merging and diffing. Below are the instructions to get that working.

  • You will need to modify your git environment. This is done through modifying the .gitconfig file found in your user folder (C:\Users\<yourname>\.gitconfig).

*Note, when you install WinMerge be sure to check the box that installs WinMerge into your system path.

    external = “c:/users/khalid abuhakmeh/difftool.sh”
[merge]
    tool = winmerge
[mergetool "winmerge"]
   cmd = ‘WinMergeU.exe’ \”$MERGED\”
   trustExitCode = false
   keepBackup = false

  • Create a bash script to execute against WinMerge. Create a file called difftool.sh and save it in the same directory. Below are the contents of my file.
#!/bin/sh
echo Launching WinMergeU.exe: $1 $2
"C:/Program Files (x86)/WinMerge/WinMergeU.exe" -e -ub "$1" "$2" | cat
#!/bin/shecho Launching WinMergeU.exe: $1 $2"C:/Program Files (x86)/WinMerge/WinMergeU.exe" -e -ub "$1" "$2" | cat

Now when you execute the commands "git diff @{1}" (compares against previous version)  or "git merge" you will get to use WinMerge to perform those actions. Pretty cool.

Conclusion

So there you have it, my initial interactions with Git and what I have learned so far. There are more things to learn, but I am definitely a convert to Git. Can you Dig Git?

shaft

No Pain, No Gain? Part 2 : Tools

0

Some developers are elite, they only code in notepad. I on the other hand don’t fall into that category; I love my tools! This post is to recognize the importance of productivity tools and realizing the pain of living without them. A good carpenter could build your house with just a hammer and a handsaw, but we all know that is a completely insane undertaking. Approaching a development project is the same. Just like any other professional, developers should hone their tools.

The Tragedy

There are developers out there only using the basic Visual Studio IDE and what Microsoft provides to them out of the box. Although these developers are creating applications, they are probably feeling the pain in two places. You can code yourself into a corner when developing using drag and drop development. I am not going to say it is evil, because drag and drop certainly has a place, but it is intoxicating. Drag, Drag, Drag, Done! You’ve just created a application, but what happens when you need to step outside of the box of the visual studio designer? Many developers freeze and panic at this point, because there is no feature in their Visual Studio toolbox for that! The other problem with drag and drop, is that developers can get into brain-dead development. Like I said, it is intoxicating to drag a new feature onto your application, but does it really need to be there? Now I am picking on drag and drop, but there is another bigger tragedy. The tragedy is that these developers don’t explore the larger ecosystem of .NET. There is cool stuff happening outside of the realm of MSDN and Microsoft guidance.

The other issue I see is that many professional developers don’t have a proper development environment. What do I mean by development environment? To me there are minimal standards for a development environment: Source Control, Local Database Engine, External Text Editor, and Reflector. That’s it for a minimal productive development environment, if you are missing any of those then you are doing yourself an injustice.

The Remedy

So you are missing some of the things I mentioned above, but don’t fret I will give you a couple of tools that can fill those places and explain how they can ease your development life.

Reflector

USE THIS! You will be better for having done so. It disassembles any .Net assembly and shows you the code inside. I have progressed my skills exponentially by just reading other peoples code. At this point in my career I would say I read more code than I write. When you are scratching your head about why a call into a third party assembly is exploding, you can use reflector to see if the problem is yours or the third party.

Source Control

I personally have used Visual Source Safe, Team Foundation Server, CVN, and SVN. I currently love SVN because it allows me the facility to host a repository locally or use many of the FREE Subversion providers on the internet. I also have great Visual Studio integration with the free add-in Ankh-SVN. I’ve included the links to some SVN providers along with the link to Ankh-SVN below. Now you have no excuse to back up your tireless efforts in coding.

You’ll thank me when your machine blows up and you still have your code safely on the net. Your Welcome!

Database Engine

This isn’t so much an issue until development teams make it an issue. I’ve been part of development environments where there was one database that everyone developed against *cough* Oracle. What a freaking nightmare. Oracle released a developer version of their database, but the damage was already done. Developers yelling “You changed my data!” at each other, on the verge of fist fights. So as a rule of thumb, every developer should have a local instance of the database in their environment. If your database is “too complex” for that then you probably have bigger problems.

Use the appropriate engines for your project : SQL Server, Oracle, MySQL,, or SQLite.

External Text Editor

image

“I already have Visual Studio, who needs this?” Visual Studio is slow to load, especially with all those plug-ins (check out my load screen!). Visual Studio is also overkill when all you need to do is change a configuration setting or look at a text file.  Waiting for Visual Studio can seriously hamper your groove, and sometimes you just don’t have that luxury. In addition, sometimes your IDE is not available because your are on another machine. I personally like Notepad2. It is quick and it is portable. It also gives you nice syntax highlighting for XML and HTML.

The Extras

Now what I mentioned above is just a minimum, but the extra tools make things better. Let’s look them over.

GhostDoc

I’d swear there was someone reading my code. This tool basically documents your code with a click. You need this if you do a lot of documentation in your code. It will literally save you thousands of commenting keystrokes.

ReSharper

A productivity tool like no other. My previous post explains it all. It is the difference between coding like the tortoise or the hare.

ORM – Object Relational Mappers

SQL is a powerful language, but I hate writing repetitive CRUD statements. An Object Relational Mapper is the way to go when designing a system. You can save hundreds of man hours not writing CRUD code and getting to what really matters. A nice introduction to Object Relational Mapping is Linq2SQL, check it out if you haven’t already.

Enterprise Library

Enterprise Library has been around for a long time and I love it. It is a set of proven industry practices packaged up for you nice and neatly. Don’t reinvent the wheel when you have a Ferrari waiting to pick you up.

In Summary

Tools are awesome, it is one of the greatest advantages we have over other development communities. You should also never get too comfortable with a tool set, because there is always something coming out that could serve you better. Tools are meant to help you do the job, they aren’t the job itself. If a tool doesn’t serve you well, then you should just avoid it and find something that works.

Go to Top