Category Archives: Version Control

Creating a Repository with Git

This assumes you have already installed git on the system in use.

Creating a new repository with git is very simple. First, using your favorite command line tool, navigate to the directory you want to start using with git. Then, it’s as simple as

git init

You could also navigate to the parent directory, and

git init

so, something like

git init my-new-project

And now you have a new directory called my-new-project that is under version control with git.

Posted in Version Control | Leave a comment

SVN Ignore

Telling SVN to ignore files and directories is crucial to keeping your repository clean, and to prevent it from needlessly bloating. It’s rather simple to tell SVN what you want it to ignore with svn propset/propedit svn:ignore.

If you want SVN to ignore all files in a directory, you’d simply enter the following command:

svn propset svn:ignore * /path/to/directory

Often times, you only want SVN to ignore a specific type of file, say .jpg uploads in your user profile pictures directory:

svn propset svn:ignore *.jpg /path/to/directory

As you can see, it’s easy to tell SVN what to ignore with propset svn:ignore, but what if you want to know what you or someone else has told SVN to ignore? It’s simply:

svn propget svn:ignore /path/to/directory

Often times, you will want to edit what you’ve already told SVN to ignore. This can be achieved with svn propedit svn:ignore.

svn propedit svn:ignore /path/to/directory

This will allow you to edit your svn:ignore property in your default text editor. Multiple ignores can be added one per line. You can even run this command to setup the initial svn:ignore rather than using svn propset svn:ignore. I much prefer this method because it’s cleaner, and I don’t have to remember the syntax for the command line.

Posted in Version Control | Comments closed

SVN – Creating a New Repository

Creating a new repository with Subversion is simple. Just run the following command on your svn server:

svnadmin create /path/to/svn/example.com

This will create a new, blank repository with the name “example.com”. Now you will want to do one of two things, import an existing project, or setup the initial directory structure for your new repository. To import an existing project, simply run the following command:

svn import /local/path/to/existing/project http://svn.example.com/path/to/svn/example.com

Now, if you are not importing an existing project you will want to setup your initial directory structure, most likely in the following fashion.

/path/to/svn/example.com/branches

/path/to/svn/example.com/tags

/path/to/svn/example.com/trunk

All you have to do is, checkout the project, create the necessary directories, and commit them to the repository. A friend of mine created a shell script to automate creating a new svn repository, and setting up the initial directory structure and/or importing an existing project.

Posted in Version Control | Comments closed

SVN Copy – Creating a Branch or Tag

Tagging and branching with svn are as simple as using the copy command. For this tutorial, I will assume that your repository has the following structure:

/path/to/repository/branches

/path/to/repository/tags

/path/to/repository/trunk

To create a tag of the trunk, run the following command:

svn copy http://svn.example.com/path/to/repository/trunk http://svn.example.com/path/to/repository/tags/snapshot-of-trunk

To create a tag of your current working copy (assuming you are in that directory on your local machine):

svn copy . http://svn.example.com/path/to/repository/tags/working-copy-seth

To tag a branch, say before merging the branch back into the trunk, run the following command:

svn copy http://svn.example.com/path/to/repository/branches/branch-seth/ http://svn.example.com/path/to/repository/tags/snapshot-branch-seth

To create a branch of the trunk:

svn copy http://svn.example.com/path/to/repository/trunk http://svn.example.com/path/to/repository/branches/branch-seth

To create a branch of your current working copy:

svn copy . http://svn.example.com/path/to/repository/branches/branch-seth

Tags should only be used to create snapshots of the repository. No development should be done on a tag, meaning you should never commit code to a tag. Branches are used for development that you do not want to interfere with everyday activity. They can be used for experimental code, code that you may only want to have run on your local machine, but still would like to have the power of version control behind your code. There are many other situations in which you would want to use a tag or a branch. You can read more about subversion and tags and branches on Wikipedia.

Posted in Version Control | Comments closed

SVN Merge – Merging a Branch Into the Trunk

So you’ve created a branch for one reason or another, mainly to make sure that the trunk stays stable and doesn’t create chaos for the other developers on your team. You’ve committed several changes to this branch and thoroughly tested them to make sure everything is in working order. Now how do you get them back into the trunk? This is how.

You should have a local copy of the branch since that is where you have done the development.

/local/path/to/repository/branch

Now, if you don’t already have a copy of the trunk locally, get one. Navigate to your local copy of the trunk.

/local/path/to/repository/trunk

You will need the revision number of the revision when you created the branch. For the sake of this example, I will say that the branch was at revision 100. Now run the following command to merge the branch into your local copy of the trunk.

svn merge -r 100:HEAD https://svn.example.com/path/to/repository/branch/my-dev-branch

You should now see that the files modified in your branch have been merged in your local copy of the trunk. Some files may be in conflict, and will have a “C” next to them in the file list after the merge command was run. You can also run an svn status to see if any files are in conflict. Resolve all conflicts, manually if necessary. Now make sure everything is working on your local copy of the trunk. If so, check your changes into the trunk.

On a side note, I like to tag the trunk before I merge a branch back into it. It just puts my mind at ease knowing I have a snapshot of a known working copy of the trunk.

Posted in Version Control | Comments closed

SVN Switch – Switching to or from the Trunk to a Branch

I recently had to make my first branch on a project using svn. Making a branch is easy enough with svn copy, but where do you go from there? You could check out a fresh copy of the branch from the repository, but you already have the environment setup and working for the trunk copy. There is an easy and elegant solution, and it lies within svn switch. First navigate to your working copy via the command line. Now to switch to a branch, or tag, in the repository, simply type:

svn switch http://svn.example.com/project/path/to/repo/branch .

Your working copy will now be the branch copy, and any committed changes will go to the branch. It is a simple and easy to use command that should speed up your development.

Posted in Version Control | Comments closed