Fixed a typo in en/grandmaster.txt
[gitmagic.git] / en / clone.txt
blob69e32b38d446321f1966003556dfdf6f680e3c3c
1 == Cloning Around ==
3 In older version control systems, checkout is the standard operation to get files. You retrieve a bunch of files in the requested saved state.
5 In Git and other distributed version control systems, cloning is the standard operation. To get files you create a clone of the entire repository. In other words, you practically mirror the central server. Anything the main repository can do, you can do.
7 === Sync Computers ===
9 This is the reason I first used Git. I can tolerate making tarballs or using *rsync* for backups and basic syncing. But sometimes I edit on my laptop, other times on my desktop, and the two may not have talked to each other in between.
11 Initialize a Git repository and commit your files on one machine. Then on the other:
13  $ git clone other.computer:/path/to/files
15 to create a second copy of the files and Git repository. From now on,
17  $ git commit -a
18  $ git pull other.computer:/path/to/files HEAD
20 will pull in the state of the files on the other computer into the one you're working on. If you've recently made conflicting edits in the same file, Git will let you know and you should commit again after resolving them.
22 === Classic Source Control ===
24 Initialize a Git repository for your files:
26  $ git init
27  $ git add .
28  $ git commit -m "Initial commit"
30 On the central server, initialize an empty Git repository with some name,
31 and start the Git daemon if necessary:
33  $ GIT_DIR=proj.git git init
34  $ git daemon --detach  # it might already be running
36 For Git hosting services, follow the instructions to setup the initially
37 empty Git repository. Typically one fills in a form on a webpage.
39 Push your project to the central server with:
41  $ git push git://central.server/path/to/proj.git HEAD
43 We're ready. To check out source, a developer types
45  $ git clone git://central.server/path/to/proj.git
47 After making changes, the code is checked in to the main server by:
49  $ git commit -a
50  $ git push
52 If the main server has been updated, the latest version needs to be checked out before the push. To sync to the latest version:
54  $ git commit -a
55  $ git pull
57 ==== Push versus pull ====
59 We mostly avoid pushing into a repository, because confusion can ensue
60 if the destination has a working directory with changes. However, pushing into
61 a bare repository is a straightforward operation and more suitable than a pull
62 in this case.
64 Pulling from the server requires shelling into the server, and also
65 knowing the network address of the machine you happen to be working on.
66 Furthermore, firewalls may interfere.
68 === Forking a Project ===
70 Sick of the way a project is being run? Think you could do a better job? Then on your server:
72  $ git clone git://main.server/path/to/files
74 Next tell everyone about your fork of the project at your server.
76 At any later time, you can merge in the changes from the original project with:
78  $ git pull
80 === Ultimate Backups ===
82 Want numerous tamper-proof geographically diverse redundant archives? If your project has many developers, don't do anything! Every clone of your code is effectively a backup. Not just of the current state, but of your project's entire history. Thanks to cryptographic hashing, if anyone's clone becomes corrupted, it will be spotted as soon as they try to communicate with others.
84 If your project is not so popular, find as many servers as you can to host clones.
86 The truly paranoid should always write down the latest 20-byte SHA1 hash of the HEAD somewhere safe. It has to be safe, not private. For example, publishing it in a newspaper would work well, because it's hard for an attacker to alter every copy of a newspaper.
88 === Light-Speed Multitask ===
90 Say you want to work on several features in parallel. Then commit your project and run:
92  $ git clone . /some/new/directory
94 Git exploits hard links and file sharing as much as safely possible to create this clone, so it will be ready in a flash, and you can now work on two independent features simultaneously. For example, you can edit one clone while the other is compiling.
96 At any time, you can commit and pull changes from the other clone.
98  $ git pull /the/other/clone HEAD
100 === Guerilla Version Control ===
102 Are you working on a project that uses some other version control system, and you sorely miss Git? Then initialize a Git repository in your working directory:
104  $ git init
105  $ git add .
106  $ git commit -m "Initial commit"
108 then clone it:
110  $ git clone . /some/new/directory
112 Now go to the new directory and work here instead, using Git to your heart's content. Once in a while, you'll want to sync with everyone else, in which case go to the original directory, sync using the other version control system, and type:
114  $ git add .
115  $ git commit -m "Sync with everyone else"
117 Then go to the new directory and run:
119  $ git commit -a -m "Description of my changes"
120  $ git pull
122 The procedure for giving your changes to everyone else depends on the other version control system. The new directory contains the files with your changes. Run whatever commands of the other version control system are needed to upload them to the central repository.
124 The *git svn* command automates the above for Subversion repositories, and can
125 also be used to
126 http://google-opensource.blogspot.com/2008/05/export-git-project-to-google-code.html[export a Git project to a Subversion repository].