Modernized command invocations a bit.
[gitmagic/dustin.git] / clone.txt
blob25f218242ebcc841788fe533e37e65629c577f01
1 == Cloning Around ==
3 In older version control systems, checkout is the standard operation to get files. You checkout 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 create a mirror of 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 as above 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 respository. From now on,
17  $ git commit -a
18  $ git pull other.computer:/path/to/files
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 Pushing is also possible. If you have not committed any changes on the other computer, you may type
24  $ git push other.computer:/path/to/files
26 to push the current state to the other computer. Next time you're logged in to the other computer, run
28  $ git checkout HEAD .
30 to update the files before working on them. Be aware that you'll lose any uncommitted changes when you do this. Because more care is required, I prefer sticking to pulls for this use case.
32 === Classic Source Control ===
34 Initialize a Git repository for your files: 
36  $ git init
37  $ git add .
38  $ git commit -m "Initial commit"
40 On the central server, initialize an empty Git repository with some name,
41 and start the Git daemon if necessary:
43  $ GIT_DIR==proj.git git init
44  $ git daemon --detach  # it might already be running
46 Some public hosts, such as http://repo.or.cz[repo.or.cz], will have a different method for setting up the initially empty Git repository, such as filling in a form on a webpage.
48 Push your project to the central server with:
50  $ git push git://central.server/path/to/proj.git HEAD
52 We're ready. To check out source, a developer types
54  $ git clone git://central.server/path/to/proj.git
56 After making changes, the code is checked in to the main server by:
58  $ git commit -a
59  $ git push
61 If the main server has been updated, the latest version needs to be checked out before the push. To sync to the latest version:
63  $ git commit -a
64  $ git pull
66 === Forking a Project ===
68 Sick of the way a project is being run? Think you could do a better job? Then on your server:
70  $ git clone git://main.server/path/to/files
72 Next tell everyone to check out your fork of the project at your server.
74 At any later time, you can merge in the changes from the original project with:
76  $ git pull
78 === Ultimate Backups ===
80 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 of the project, 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.
82 If your project is not so popular, find as many servers as you can to host clones.
84 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.
86 === Light-Speed Multitask ===
88 Say you want to work on several features in parallel. Then after committing your project:
90  $ git clone --local --shared . /some/new/directory
92 The options can be written as *-l -s* instead, which I like to think of as an acronym for "Light Speed"!
94 Git exploits hard links and file sharing as much as possible to create this clone. Subsequently, this clone is unsuitable as a backup. However, it's 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
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, at light speed:
110  $ git clone -l -s  . /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.