Book Giveaway & Exclusive Chapter: Pragmatic Version Control Using Git
Join the DZone community and get the full member experience.Join For Free
DZone and Pragmatic Bookshelf have partnered to bring you this exclusive chapter from 'Pragmatic Version Control Using Git' (by Travis Swicegood).
Creating Your First Project
Now it’s time to dig into Git. Up to this point, we have talked about abstract ideas and getting set up. That changes in this chapter.
We’re going to work on a small HTML project and use Git to track it. Don’t worry if you don’t know HTML. The markup we’re using here is simple and easy to follow even if you aren’t familiar with HTML.
- Create a repository
- Add some files and make some changes
- Create a new branch
- Tag a release and clean up our repository release
- Clone a repository
Once we’re finished, you’ll know the basics you need to get started with Git. This chapter is a high-level overview. There are a lot of new concepts and commands introduced to get you started.
We’ll be covering the commands and concepts introduced here pretty quickly, but each section has references to later parts in the book in case you can’t wait to learn more about something we’re talking about.
I encourage you to follow along with the examples in this chapter and the rest of the book, executing all the commands yourself. We learn via repetition, whether it’s our multiplication tables in grade school or typing a Git command into the command prompt.
3.1 Creating a Repository
Creating a repository in Git is simple, but it seems peculiar if you’re coming from Subversion or CVS. Your repository is something that exists separate from your copy of it in most VCSs. Your repository in Git is stored right alongside your working tree in a directory called .git.
To create a repository in Git, you first need to decide where you want to store your project’s code. In this example, we’re going to create a simple HTML page, so let’s call our project mysite. You need to create
a directory of the same name; then change into it, and type git init. The whole process should look something like this:
prompt> mkdir mysite
prompt> cd mysite
prompt> git init
Initialized empty Git repository in /work/mysite/.git/
You’re done. You now have a Git repository that is ready to start tracking
“But there must be more!” you cry. Actually, no. Setting up a Git repository
is an extremely lightweight operation. The git init command sets up
a directory called .git that stores all the repository metadata, and the
empty directory we’re in, mysite, serves as the working tree of code you
have checked out from the repository.
The above excerpt was extracted from Pragmatic Version Control Using Git, published in December 2008 by Pragmatic Bookshelf. It is being reproduced here by permission from Pragmatic Bookshelf. For more information or to purchase a paperback or PDF copy, visit the Pragmatic Version Control Using Git homepage.
© 2008 Travis Swicegood. All rights reserved. No part of this publication
may be reproduced, stored in a retrieval system, or transmitted, in any
form, or by any means, electronic, mechanical, photocopying, recording,
or otherwise, without the prior consent of the publisher.
Opinions expressed by DZone contributors are their own.