112 lines
		
	
	
		
			3.2 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
			
		
		
	
	
			112 lines
		
	
	
		
			3.2 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
| ---
 | |
| layout: reference
 | |
| ---
 | |
| 
 | |
| <div class="box">
 | |
|   <h2>Getting and Creating Projects</h2>
 | |
|   <div class="block">
 | |
|     <p>
 | |
|     In order to do anything in Git, you have to have a Git repository.  This
 | |
|     is where Git stores the data for the snapshots you are saving.
 | |
|     </p>
 | |
| 
 | |
|     <p>
 | |
|     There are two main ways to get a Git repository.  One way is to simply
 | |
|     initialize a new one from an existing directory, such as a new project or
 | |
|     a project new to source control.  The second way is to clone one from a
 | |
|     public Git repository, as you would do if you wanted a copy or wanted to
 | |
|     work with someone on a project.  We will cover both of these here.
 | |
|     </p>
 | |
|   </div>
 | |
| </div>
 | |
| 
 | |
| <div class="box">
 | |
|   <h2>
 | |
|     <span class="docs">
 | |
|       <a href="#">docs</a>  
 | |
|       <a href="#">book</a>
 | |
|     </span>
 | |
|     <a name="init">git init</a>
 | |
|     <span class="desc">initializes a directory as a Git repository</span>
 | |
|   </h2>
 | |
| 
 | |
|   <div class="block">
 | |
|     To create a repository from an existing directory of files, you can
 | |
|     simply run <code>git init</code> in that directory.  For example,
 | |
|     let's say we have a directory with a few files in it, like this:
 | |
| 
 | |
| <pre>
 | |
| $ cd konichiwa
 | |
| $ ls
 | |
| README   hello.rb
 | |
| </pre>
 | |
| 
 | |
|     This is a project where we are writing examples of the "Hello World"
 | |
|     program in every language.  So far, we just have Ruby, but hey, it's
 | |
|     a start.  To start version controlling this with Git, we can simply
 | |
|     run <code>git init</code>.
 | |
| 
 | |
| <pre>
 | |
| $ git init
 | |
| Initialized empty Git repository in /opt/konichiwa/.git/
 | |
| </pre>
 | |
| 
 | |
|     Now you can see that there is a <code>.git</code> subdirectory in your
 | |
|     project.  This is your Git repository where all the data of your
 | |
|     project snapshots are stored.
 | |
| 
 | |
| <pre>
 | |
| $ ls -a
 | |
| .        ..       .git     README   hello.rb
 | |
| </pre>
 | |
| 
 | |
|     Congratulations, you now have a skeleton Git repository and can start
 | |
|     snapshotting your project.
 | |
| 
 | |
|   </div>
 | |
| </div>
 | |
| 
 | |
| <div class="box">
 | |
|   <h2>
 | |
|     <span class="docs">
 | |
|       <a href="#">docs</a>  
 | |
|       <a href="#">book</a>
 | |
|     </span>
 | |
|     <a name="clone">git clone</a>
 | |
|     <span class="desc">copy a git repository so you can add to it</span>
 | |
|   </h2>
 | |
|   <div class="usage">
 | |
|     git clone (url) [directory]
 | |
|   </div>
 | |
|   <div class="block">
 | |
|     <p>
 | |
|     If you need to collaborate with someone on a project, or if you want to
 | |
|     get a copy of a project so you can look at or use the code, you will
 | |
|     clone it.  You simply run the <code>git clone [url]</code> command with 
 | |
|     the URL of the project you want to copy.
 | |
|     </p>
 | |
| 
 | |
| <pre> [example] </pre>
 | |
| 
 | |
|     <p>
 | |
|     This will copy the entire history of that project so you have it locally
 | |
|     and it will give you a working directory of the main branch of that project
 | |
|     so you can look at the code or start editing it.  If you change into the
 | |
|     new directory, you can see the <code>.git</code> subdirectory - that is
 | |
|     where all the project data is.
 | |
|     </p>
 | |
| 
 | |
| <pre> [example] </pre>
 | |
| 
 | |
|     <p>
 | |
|     By default, Git will create a directory that is the same name as the 
 | |
|     project in the URL you give it - basically whatever is after the last slash
 | |
|     of the URL.  If you want something different, you can just put it at the
 | |
|     end of the command, after the URL.
 | |
|     </p>
 | |
| 
 | |
|   </div>
 | |
| </div>
 | |
| 
 | |
| <p><a href="/basic">On to Basic Snapshotting »</a></p>
 |