Correction on effects of git-checkout
[gitmagic.git] / clone.txt
blobcff09cbeebed2ebdc9d19dfa40bed9b4db9cfeb1
1 = Cloning Around =
3 In older version control systems, checkout was the standard way to get a saved state. You'd checkout a bunch of files in the requested saved state.
5 In Git and other distributed version control systems, the standard way to get files is to create a clone of the entire repository. In other words, you practically create a mirror of the central repository. So anything the central 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 <tt>rsync</tt> for backups and basic syncing. The problem was sometimes I'd edit on my laptop, other times on my desktop, and they 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 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.
32 == Classic Source Control ==
34 Initialize a Git repository for your files: 
36  $ git-init-db
37  $ git add .
38  $ git commit -m "Initial commit"
40 On the central server, initialize an empty Git repository with some name:
42  $ GIT_DIR=proj.git git-init-db
44 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.
46 Push your project to the central server with:
48  $ git-push git://central.server/path/to/proj.git HEAD
50 We're ready. To check out source, a developer types
52  $ git clone central.server:/path/to/proj.git
54 After making changes, the code is checked in to the main server by:
56  $ git commit -a
57  $ git push
59 If the main server has been updated, the latest version needs to be checked out before the push. To sync to the latest version:
61  $ git commit -a
62  $ git pull
64 == Forking a Project ==
66 Sick of the way a project is being run? Think you could do a better job? Then on your server:
68  $ git clone main.server:/path/to/files
70 Next tell everyone to check out your fork of the project at your server.
72 At any later time, you can merge in the changes from the original project with:
74  $ git pull
76 == Ultimate Backups ==
78 Want numerous tamper-proof geographically diverse redundant archives? If your project has many developers, don't do anything! Everyone who clones 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 someone's clone become corrupted, it will be spotted as soon as they try to communicate with others.
80 If your project is not so popular, find as many hosts as you can and clone your project there.
82 For the truly paranoid, 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.
84 == Light-Speed Multitasking ==
86 Say you want to work on several features in parallel. Then after committing your project, clone it:
88  $ git-clone --local --shared . /some/new/directory
90 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 you can work on two independent features simultaneously.
92 For example, you can edit one while the other is compiling. At any time, you can commit and pull changes from one to the other.
94  $ git-pull one /to/the/other
96 == Guerilla Version Control ==
98 Are you working on a project that uses some other version control system, and you sorely miss some Git features? Then initialize a Git repository in your working directory:
100  $ git-init-db
101  $ git add .  # you may want to exclude certain files, such as those
102               # belonging to the other version control system
103  $ git commit -m "Initial commit"
105 then clone it:
107  $ git-clone . /some/new/directory
109 Now go to the new directory and work here instead, and use Git to your heart's content. Once in a while, you'll want to sync with everyone else, in which case first sync the original directory using the commands appropriate to the other version control system, and type:
111  $ git add .
112  $ git commit -m "sync with everyone else"
114 Then go to the new directory and run:
116  $ git commit -a -m "description of my changes"
117  $ git pull
119 On the other hand, the procedure for giving your changes to everyone else varies depending on the other version control system. You have the files you want to push in the new directory, and running a few commands of the other version control system will upload them to the central repository.