Getting Started with Subversion or Git
Join the DZone community and get the full member experience.
Join For FreeA 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
|
Cons
|
Git
Pros
|
Cons
|
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/
Opinions expressed by DZone contributors are their own.
Comments