Git –newbie –workflow
Mar 3rd
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.
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):
- init or clone: if you are starting a repository use init, if you are getting use clone.
- branch: create a new branch to start working in or just work in the master branch.
- add: add any or all files involved in your project.
- commit: commit staged files to your local source repository.
- pull: get any changes that have occurred at the central repository.
- merge or rebase: make sure all your changes and branches are reflected in the master if need be.
- 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.
- 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.
[/diff]
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?
New Year – New Developer
Jan 4th
So we are sitting on what is the precipice of a new year. We can either choose to change and evolve with the times, or we can stay stuck in our ways. I have decided to make some new year’s resolutions to make me a better person and developer.
1. Get Into Shape
As developers we can spend a lot of our time on our butts, up to 8 hours a day. That is why I need to make a strong effort to be active. My definition of active is a solid hour of exercise five to six days a week. Exercise is only part of the solution. Did you know your body expends more calories digesting food then it does when you exercise? That is why I have to make an effort to eat less calories. Now that the holiday season is over, the temptation of gorging is gone with it. And finally, cut out all high-sugar drinks. Developers live off of energy drinks but each can of energy drink can be as much as 400 calories. That is equivalent to the calories found in a bagel! Replacing those drinks with water can cut out a lot of unnecessary calories.
2. Work On My Communication Skills
I can talk to people, but sometimes I don’t fully get my idea across. This can cause frustration on both my part and the listener. That is why I have to work on my communication skills. I will do this by being more conscious of the words I say, listen deeply to my counterpart, and being less abrupt with my answers. I will also be working on my vocabulary. Adding words to my vocabulary can give me a more diverse set of words to express my ideas and intentions.
3. Swear Less
Swearing is a powerful tool when used properly. It can express frustration, anger, and happiness all in a couple words. There have also been studies that show swearing can lead to better rapport between co-workers. That being said, I have to remember that there is a place and time to use certain words and phrases. For example, a holy place is no place to start dropping the F-Bomb.
4. Be More Systematic
I am trying more and more to depend on systems to make me more efficient and dependable. This will help me reduce times where I am just thinking of what to do instead of doing what I need to do.
5. Be More Assertive
Over my life I’ve learned that people can take advantage of you if you let them. They can also mistake your kindness for weakness. Letting the other party know why I won’t do something, or the conditions on what I’ll do given a task will make my life much simpler.
6. Give Love to the People that Deserve It
There are a lot of important people in my life, and some not that important. Giving more preference to those I love will make everyone happier.
7. Read, Read, Read
It’s surprising how much more knowledgeable you get by just reading what other people are doing. So I am dedicating 2010 to reading more.
The year is early and things could change, but for right now these are my resolutions. Do you have any?
Dictionary of U.S. States
Nov 10th
This post is not exactly ground breaking but can be very useful when you have objects that have a State property. It is this kind of stuff that can kill your development mojo and slow you down. That is why I posted it on here, so you can move on to the more important stuff.
public static class USStates
{
public static readonly Dictionary States = new Dictionary
{
{"AL"," Alabama"},
{"AK"," Alaska"},
{"AZ"," Arizona"},
{"AR"," Arkansas"},
{"CA"," California"},
{"CO"," Colorado"},
{"CT"," Connecticut"},
{"DE"," Delaware"},
{"FL"," Florida"},
{"GA"," Georgia"},
{"HI"," Hawaii"},
{"ID"," Idaho"},
{"IL"," Illinois"},
{"IN"," Indiana"},
{"IA"," Iowa"},
{"KS"," Kansas"},
{"KY"," Kentucky"},
{"LA"," Louisiana"},
{"ME"," Maine"},
{"MD"," Maryland"},
{"MA"," Massachusetts"},
{"MI"," Michigan"},
{"MN"," Minnesota"},
{"MS"," Mississippi"},
{"MO"," Missouri"},
{"MT"," Montana"},
{"NE"," Nebraska"},
{"NV"," Nevada"},
{"NH"," New Hampshire"},
{"NJ"," New Jersey"},
{"NM"," New Mexico"},
{"NY"," New York"},
{"NC"," North Carolina"},
{"ND"," North Dakota"},
{"OH"," Ohio"},
{"OK"," Oklahoma"},
{"OR"," Oregon"},
{"PA"," Pennsylvania"},
{"RI"," Rhode Island"},
{"SC"," South Carolina"},
{"SD"," South Dakota"},
{"TN"," Tennessee"},
{"TX"," Texas"},
{"UT"," Utah"},
{"VT"," Vermont"},
{"VA"," Virginia"},
{"WA"," Washington"},
{"WV"," West Virginia"},
{"WI"," Wisconsin"},
{"WY"," Wyoming"},
{"AS"," American Samoa"},
{"DC"," District of Columbia"},
{"FM"," Federated States of Micronesia"},
{"MH"," Marshall Islands"},
{"MP"," Northern Mariana Islands"},
{"PW"," Palau"},
{"PR"," Puerto Rico"},
{"VI"," Virgin Islands"},
{"GU"," Guam"}
};
public static IList GetAbbreviations()
{
return States.Keys.ToList();
}
}
I have also included Commonwealths and Territories. I have excluded Military states like “Armed Forces Africa”. The list I used can be seen at 50States.com. This list should be good for a long time.
Visual Studio 2010 Without ReSharper 5.0
Nov 5th
I’ve started a new project in Visual Studio 2010 because I want to take advantage of the new features in ASP.NET MVC 2. The features I am really interested in are Areas and the support of the new client side validation libraries that utilize the Data Annotations attributes. I sat down and set up my new solution as usual. Everything at this point was going great. Rolling up my sleeves, after several minutes of coding the ReSharper 5.0 nightly build started barfing on me. The shortcut keys barely worked and it would constantly freeze VS2010 when viewing Html pages. Ultimately, I realized that ReSharper 5.0 was not ready for VS2010, although it works great in VS2008. Now I was faced with the cold reality of having to uninstall ReSharper, for the greater good of the project. I haven’t coded a project without ReSharper in about two years, but now I am venturing forth until ReSharper 5.0 can catch up with me. Below, I’m going to list the things that I miss most about development life with ReSharper.
1. Development Time Error Checking
Resharper tells you that you’ve made a mistake before you ever compile your solution. It is constantly compiling you application in the background and making sure everything is still gravy. This keeps you from hitting f5 or Ctrl+Shift+B every ten seconds. This has to be the feature I miss the most. This is definitely a feature Microsoft should look into building directly into future versions of Visual Studio. Wouldn’t you like to know that you typed something wrong the second you type it wrong? In addition to finding your mistakes, it places a nice little sidebar to tell you where you can find where you went wrong.
2. Solution Wide Searches for Dependencies
Resharper is really smart about what classes you are using. It can search through your entire solution and add any dependency to your existing project. This greatly reduces the need to right click on a project and click the “Add Reference” option. It even remembers third party assemblies and can add them; assemblies like NUnit or Enterprise Library.
3. Ctrl + Click = Magic
ReSharper lets you hold down the control key on your keyboard and click on a class name, which instantly takes you to the source of that class. Can greatly speed up you navigational abilities.
4. ReSharper Test Runner
ReSharper has a great test runner which runs almost all unit testing frameworks. The alternative for me right now is running tests using TestDriven.Net and Gallio, which isn’t too bad but it isn’t as nice a workflow as using ReSharper.
5. The Super Shortcut Alt+Enter
Alt+Enter, remember that key combination if you want to be a coding ninja. A super shortcut in ReSharper that understands the context you are in and shows you appropriate actions. Want to remove unused namespaces? Move your cursor to the namespaces section of your code and press Alt+Enter. Want to use var instead? Alt+Enter. Want to rename a file to match a class name? Alt+Enter. Want to move a class to a namespace? Alt+Enter. Want to rule the world? Alt+Enter (coming in ReSharper 6).
6. Smarter Templates
If you use code snippets in Visual Studio then you owe it to yourself to look at the templates in ReSharper. You can create really smart templates that include things like namespaces, filename, and much more. This feature has save my fingers countless hours of typing.
Conclusion
I miss ReSharper, but the advantages to using VS 2010 greatly outweigh my selfish need to be comforted by a productivity tool. Until ReSharper 5 becomes more stable I will have to wander the development wilderness alone. Lets hope that isn’t too long.



