Information Technology Reference
In-Depth Information
In contrast, you must use command-line access to set up Subversion for a project. After set-up, many basic fea-
tures are also available in the UI. Subversion requires an external server. Git can be used locally, and it can also
support server-based development.
CAUTION
Git and Subversion are part of the command-line utilities that are installed with Xcode. To use them, check the
System Tools box when you install Xcode. If you don't do this, they're not available.
Understanding Git
Source control tools work with a repository or repo
—
a database configured to manage the files in a project. A
key benefit of professional source control is that the contents of a repo can be kept on a single Mac or shared,
either on a private server or online. It's possible to copy, or clone, repositories to duplicate them across multiple
Macs. Online storage with a service such as GitHub (
github.com
)
gives you “free” backups—a remote copy of
your source code is always available—and also supports collaborative development.
Repositories can store either incremental changes to files or complete files. Subversion stores incremental
changes. Git stores complete files; in fact, it always works with a complete local version of the entire project.
This makes it more robust than Subversion, at the cost of extra disk space and download/upload times. Because
code files are usually small, the time penalty isn't usually significant. Because Git doesn't need to merge and up-
date files, it can feel more responsive.
To use Git, you create a repository, either locally using Xcode or manually on a remote server, and then add and
edit files in the usual way. After each significant edit, you commit the changes
.
This creates a complete snapshot
of the project and adds copies of any modified or added files to the repository.
Commits don't have to proceed in a linear order. You can create a new branch to experiment with code or work
on certain features independently. Branches can develop independently, or they can be merged together.
If you work with Git locally, version control is automatic. Git tracks your commits, and you can use a new
Xcode feature called the Version Editor to view and compare the changes to each file as the project develops.
CAUTION
When you make commits you're updating multiple files at the same time. There's no automated way to revert a
single file to an earlier state without also changing other files that were committed at the same time. However,
you can use simple manual copy/paste to copy an old version of a file from the Version Editor into the main code
editor and then create a new commit with the old contents of the file.
If you use a remote server, the process becomes more complex. To use Git remotely, collaborators need to sup-
ply a name, an e-mail address, and a public key for security. If you are managing a Git project, you can review
and accept or decline commits supplied by other developers.
When you work with an online repo, you can clone a project—copy the current version from the server to your
Mac—to work on it independently and then perform a push to merge your changes back into the source. The
lead developer can then review the changes and accept or delete them. When you work collaboratively, Git and