Notes about SVN and Mac

Submitted by rdrink on Sat, 06/26/2010 - 06:07

Printer-friendly versionPrinter-friendly version

I started this as a comment to Ed's post but decided to make it it's own. I wanted add a few notes, especially for first time svn users and especially for Mac users...

One thing that is important to understand it that svn is extremely sensetive to the directory (folder) structure of your hard-drive. So unlike your usual Apple experience, where you can move files around when-ever you want to where-ever you want, svn assumes that when you do your first check-out you are doing it in the folder that you will always want that project to be in... and there is no thought, or possibilty, that it will be moved later [and if you do move it you are in for a world of hurt].

So for Mac users, especially those new to the Terminal (and if you are really really new: it can be found in Applications -> Utilities) it is important to familiarize yourself with the commands cd (change directory) ls (list directory)  mkdir (make directory/folder) and pwd (print working directory). There are lots of good references for terminal commands on the web but for now I will illustrate just these to get you started.

It is also important that Mac users know that you will not find the 'home' folder mentioned in Ed's example, Instead on Mac your home folder is you user name. If you double-click on your hard-drive and open a Finder window, in the lefthand column you will see a little icon of a house like this this is your home folder (house=home, get it?) and next to it is your username. So on Mac your home folder is your username.

What you will also notice is that the Teminal uses the same username. For example my username is rdrink so when I open the Terminal what I see is

Wanderer:~ rdrink$

showing me that I am user rdrink. Also worth pointing out is that Wanderer is tha name of my computer, and more importantly after the : the ~ (tilde) means we are in the/my home directory. So if you were to describe the above in a sentence you would say "The user rdrink, on the computer Wanderer, is in his home directory".  Obviously then ~ is a short-hand for 'home'. Here are a few examples to illustrate this:

If I type...

Wanderer:~ rdrink$ cd ~

[in all these examples I will include the Wanderer:~ rdrink$ part so you get a sense of what my Terminal looks like. Yours of course will be different depanding on your computer and user name. However everything after the $ are the commands].

... nothing appears to happen. And that's fine, because I am already in my home directory (~) and doing a cd ~ just brings me to the same directory I am already in. Here then here is a better example:

If I type...

Wanderer:~ rdrink$ cd /Users

I get...

Wanderer:Users rdrink$ 

Note that the directory name changed from ~ to Users, to show us that we have moved from my home directory to the Users directory. If I then type...

Wanderer:~ rdrink$ ls

... I get...

Shared   rdrink
Wanderer:Users rdrink$cd /Users

which is a listing (ls) of the contents of directory /Users. (This is exactly like if you go to the Finder and double click on your hard-drive you will open a window. If you then click on the name of your hard-drive... Mac_HD, or whaterver you have named it... you will then see a folder Users. Double-click that and you will see the Shared folder and your home folder, with the house icon.)

So now that you understand how to navigate around let's use some of these commands.

First let's go back to our home directory like this...

Wanderer:Users rdrink$ cd ~

Now that we are in the home directory we can see what's in it by using ls to list everything...

Wanderer:~ rdrink$ ls

I have a lot in my home folder so I won't show you the listing, however on my machine and probably yours as well, there is a directory called Documents. This would seem to be a good place to keep my SVN code so I will switch to there, again using the cd command...

Wanderer:~ rdrink$ cd Documents/

note the trailing slash. It's optional but I put it there becausee this is a directory and also because there will be times when you see it. In fact now is a great time to introduce you to the command pwd. If I type pwd I get...


which shows us that I am in the /Documents folder, which is in my home folder (/rdrink), which is in /Users.

Now that we have successfuly navigated to my Documents folder I could go ahead a do my svn checkout. However in Ed's example he has a folder svn where he checks out his stuff to, and following his example we should do the same. What we need then is a directory svn and we are going to make it using the mkdir command. To do so you type mkdir followed by the name of the directoery, like this..

Wanderer:Documents rdrink$ mkdir svn

note that you will return back to the command line. This sometimes confuses people as the expect to go to the directory they have just created. However the command did what we asked and simply created the directory svn. If you want see it you can use the ls command and it will be listed. However more importantly this is the folder we want to be in when we checkout, so we need to change to that directory with the cd command...

Wanderer:Documents rdrink$ cd svn

and now we are in our new svn directory and finally ready to do our svn checkout! If you ever doubt which folder you are in and want to be absolutely sure you can always use the pwd command and you should see...


Obviously in the future we won't need to create the svn folder again, we simply navigate to it and do our checkout. It's also woth pointing out that one could just as easily made the svn folder from the finder by going to the home folder, then Documents, then to the File menu 'New Folder'. However I showed you the above as good exercise in learning how to use the Terminal command-line tools.

So there you have it. You now know how to use the Terminal and the command-line commands to navigate to dirrefent folders, create a new one if you need to, and you are ready to do the svn checkout outlined in Ed's posts.


One final note: when Mac users have installed Subversion (the svn system) on their machine they can do checkouts, commits, and all the other svn functions directly from the finder, without having to use the Terminal.

In the finder click on your home icon, then the documents folder. When you see the svn folder right-click (or control-click) on it and a menu opens with options like changing the folder color. At the bottom you will see More... and if you go there you will see Subversion... where you will see options fo checkout, etc. This is a great feature for Mac users however I suggest you use the Terminal and the commands outlined here and Ed's post to get used to using svn from the terminal, because the termonal will always be availible on every computer.