Adam Leggett has worked as a software consultant to UK FTSE 500 companies for over 12 years. He specializes in enterprise Java technologies, Cloud computing and agile ALM tooling. Adam is a DZone MVB and is not an employee of DZone and has posted 7 posts at DZone. View Full User Profile

Getting Started with Subversion or Git

09.20.2010
| 2047 views |
  • submit to reddit

A guest post by Mark Bathie, CTO of Codesion – a provider of version control hosting in the cloud.

For most software developers the question is not whether you should use version control, rather, what version control tool you should use. The most widely adopted is Subversion, but Git is the fastest growing.

Both are good, popular choices, but there are some core differences. Subversion, a centralized version control system, forces all developers to commit to a central server, whereas Git, a decentralized system, encourages many-to-many merging. For example, with Git you can merge to a fellow developer before merging with a central node (if there is one). There are other key differences I explore in this blog post and summarized below.

Subversion

Pros
  • Centralized control, meaning its easier to keep one official history. Good for backups, accountability and security.
  • Security: Native subdirectory-level user access restrictions
  • Branches are easy and stored centrally
  • Gentlest learning curve for newbies, and operations like branching become quite intuitive as you progress
  • Ability to lock files, ensuring that others don’t work on the same binary files assets like documents & media files simultaneously
  • Widest adoption amongst developers
  • History of changes can’t be modified
Cons
  • Working offline means you can’t commit changes to the centralized repository until you have Internet connection, although this does not prevent developers from working on their local copy.
  • Generally slower than Git, since most operations need to synchronize with the central server, especially when merging large branches
  • Possible to revise history and preserve only their successes, not their failures

Git

Pros
  • Decentralized model means many operations are faster, and makes offline work more practical
  • More merge options which are generally faster than Subversion
  • Branching is easier and faster
  • Comes with many tools like ‘bisect’ that can partly automate the process of finding where a bug was introduced
Cons
  • The local copy model means you need to be more careful of backing up your own workstations
  • The large set of commands can be esoteric and present a steeper learning curve
  • There are no locking for files which can cause issues with binary files
  • History can be changed, being able to edit past commits might not leave the strong paper-trail you’d prefer

Now that you’ve chosen your version control system (or your team has chosen for you), you’ll want to get up and running quickly. Here are some of the basics you’ll need to checkout and commit to a Subversion or Git repository.

If you’re creating a new project from scratch, you’ll need to add some files to a fresh repository. The first step is to create the blank repository. You may need to talk to your sysadmin to set this up for you, or use a cloud provider like Codesion. Once you have your repository access URL, checkout your files.

Checkout and Commit Using Subversion

Checkout your repository from the server to your local computer (your sandbox).
$> svn checkout –username mbathie https://myorg.svn.codesion.com/mywidget

Now change into the directory and add a file.

$> cd mywidget

$> echo ‘echo “hello world”’ > hello.bash

Tell Subversion it should include this file (and any others) in the next commit, and in the repository from now on. Do this by using the “svn add” command.

$> svn add *

A    hello.bash

Then commit your new files to the server.

$> svn commit -m “adding my first file”

Adding         hello.bash

Transmitting file data ..

Committed revision 1.
Checkout and Commit Using Git

Checkout your repository from the server to your local computer (your sandbox).

git clone https://mbathie@myorg.git.codesion.com/mywidget.git
This will prompt for your password, and then display the following

$> git clone https://mbathie@myorg.git.codesion.com/mywidget.git

Initialized empty Git repository in /mywidget/.git/

Password:

Change into the directory and add a file.

$> cd mywidget

$> echo ‘echo “hello world”’ > hello.bash

Tell Git it should include this file (and any others) in the next commit, and in the repository from now on. Do this by using the “git add” command.

$> git add hello.bash

Commit the file to your local Git repository.

$> git commit -m “my first commit” hello.bash

Share your changes with other team members. In this case, we’ll push the changes to the designated central repository.

$> git push origin master

The remote Git server will respond with something like the following.

$> git push origin master

Password:

Counting objects: 3, done.

Writing objects: 100% (3/3), 228 bytes, done.

Total 3 (delta 0), reused 0 (delta 0)

To https://mbathie@myorg.git.codesion.com/mywidget.git

* [new branch]      master -> master
Joining an existing project is essentially the same process as creating a new one, except when you perform the initial checkout or clone operation, you’ll be pulling down the files relevant to the project you are joining. You won’t be checking out a blank repository. You can then use the same commands above to add, commit and push your changes and share them with other team members.

 

From http://blogs.mikeci.com/2010/09/17/getting-started-subversion-git/

Published at DZone with permission of Adam Leggett, author and DZone MVB.

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)