Outsourcing your source control (my Git cheat-sheet)

As I’ve discussed, I’ve decided to sway away from my own TFS implementation at my house. Instead, I was looking for some (ideally free) repository that was private, where I could do version control for my personal projects.

As it turns out http://bitbucket.org offers just that: unlimited private repositories (with up to 5 contributors). They support either Mercurial or Git.

If you’ve ever done anything with either on .NET, you know that both of these are… not great. Both Mercurial and Git in Visual Studio are a patchwork of command-line, bad windows UI’s, and fragile VS add-on’s. This collection is supposed to make one comprehensive product (for each respective technology), however, it’s pretty tough to use.

So for now, let’s start simple. Git is trendy at the moment, let’s try that. Let’s use Git from the command-line. You can download Git for Windows from here:

http://msysgit.github.com/

Also, I decided to pick a book on it – because it’s certainly not obvious and intuitive to use. From that book (which is pretty decent, by the way), I was able to at least figure out how to get my source INTO a Git repository and do basic command-line updates.

So – for my reference (and this may help you, too) – if you want to get your personal source code off your hard drive and stored someplace private, and backed up, for free, here are the steps:

Step 1: Set up bitbucket.org


Go to http://bitbucket.org and create a free account. Once logged in, under the Repositories main menu, click on Create Repository. you’ll see something like this:

image

Note that I chose Git as the repository type – and I think it’s pretty cool that they go include issue tracking and a wiki for documentation too! I have the “Name” match the name of the Visual Studio solution (minus the “_Solution” suffix).

When done, you will see the landing page for your project, which has a useful bit of information on it:

image

Step 2: Set up your file system

Assume you have a container for all of your source-controlled code – let’s say _BitBucket. Under that, I have a container for this particular source control project “SederSoftware.MyProject”. Then, under that I have the traditional bin, docs, and src. Within src, I have my Visual Studio solution:

image

Presumably, I could have many bitbucket “projects” under C:_BitBucket that each point to separate bitbucket repositories.

Step 3: Add to source control, and push to bitbucket

Here is where the cheat-sheet comes in, because you basically do all of this from the command-line and it’s not exactly obvious. However, except for a few variables, you would do this every time – changing out only the directory name, URL, and the alias (myProject) to something meaningful for this particular project:

So, here is quick run-down of what we are doing:

  • C: [go to the C: drive, if we’re not there]
  • cd _BitBucketSederSoftware.MyProject [go to our root directory of our project]
  • git init [Initialize this directory as a local Git repository]
  • git add . [Add all files to this repository]
  • git commit -m “Initial commit” [commit these added files, adding a message/label]
  • git remote add myProject https://MyBBUser@bitbucket.org/MyBBUser/sedersoftware.myproject.git [set up an “alias” for that crazy-long URL of my project, call the alias “myProject”. Note that we got that URL from the repository page on bitbucket, it gives you this full URL, there.]
  • git push -u myProject master [push my local repository up to the myProject alias project, in the “master” stream]

You can now see on bitbucket that your source is loaded up there. Go into that repository on bitbucket, click on the “Source” tab and you can drill down and see your directories.

You might note too that you probably don’t want to include the bin and obj folders, and probably other files/directories too. You can place a .gitignore file in the root and specify what to NOT-add to the repository. You use one literal or regex per line of what you want to exclude (without quotes), like “bin” “obj” etc.

At this point, you have a local git repository, and you’ve added your source files to it, then committed and pushed those changes up to bitbucket – which is presumably your main trunk.

For those that have been victimized by ClearCase, this is akin to “delivering” my “development stream” to the “integration stream”. This is where “development stream” means my local repository in C:_BitBucket and “integration stream” represents the Git repository for this project on bitbucket.

Next steps…

So what about making changes to files and pushing the changes up to bitbucket? Well, you can always just re-do that “git add .” then a new “git commit”, then “git push”, but that is kind of tedious and very… “command-line-y”. In other words, you could edit files in Visual Studio and when you are ready to push up your changes, you would dump out to the command-line and run those commands off the top-of-your-head. It’s a very 1990’s approach, for sure!

For a UI – you can run “git gui” or “gitk” – but I would really like something integrated into Visual Studio where I can check-in, check-out and do regular source code repository work. After all, most developers are used to SourceSafe, TFS, PVCS, ClearCase, etc – so it would be nice if there was something analogous to these, for git.

I installed the “GIT extensions” for Visual Studio 2010 from Extension Manager but as-expected, those are difficult and counter-intuitive to work with. I’m still trying to figure out how to use them.

image

They have that “open-source feel” too where when I try to do something the add-in either hangs or crashes Visual Studio. Very frustrating, ugh.

I’ll do a separate post if/when I get that working. If not, we are stuck with doing command-line to commit/push changes to our repository. At the very least, your source code is now in a real repository, backed-up, and not sitting only on your hard drive.

If I can get VS integration working, I will that as a Part II of this blog post.

Posted in Best-practices, Infrastructure, New Technology, Organization will set you free, Professional Development, Team Foundation Server, Uncategorized, Visual Studio
One comment on “Outsourcing your source control (my Git cheat-sheet)
  1. […] development over there too. You’re already all set up for it, and you’ve probably learned how to use Git from the Mac command-line, […]

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Archives
Categories

Enter your email address to follow this blog and receive notifications of new posts by email.

Join 4 other followers

%d bloggers like this: