@git / git-reference / commits / f922c71

added git remote and started in on the branching section

Scott Chacon committed Jun 5, 2010 at 17:18 UTC f922c71dbacd8e681d46d5c1f877e2db58dcb5b8
2 files changed +144 -2
_layouts/reference.html
+1
@@ -69,6 +69,7 @@
69 <ul>
70 <li><a href="/remotes/#fetch">fetch, pull</a></li>
71 <li><a href="/remotes/#push">push</a></li>
72 + <li><a href="/remotes/#remote">remote</a></li>
73 </ul>
74 </div>
75
remotes/index.html
+143 -2
@@ -10,10 +10,149 @@ layout: reference
10 Sharing and Updating Projects
11 </h2>
12 <div class="block">
13 + <p>
14 + Git doesn't have a central server like Subversion. All of the commands
15 + so far have been done locally, just updating a local database.
16 + To collaborate with other developers in Git, you have to put all that
17 + data on a server that the other developers have access to. The way Git
18 + does this is to syncronize your data with another repository. There
19 + is no real difference between a server and a client - a Git repository
20 + is a Git repository and you can syncronize between any two easily.
21 + </p>
22 +
23 + <p>Once you have a Git repository, either one that you set up on your
24 + own server, or one hosted someplace like GitHub, you can tell Git to
25 + either push any data that you have that is not in the remote repository
26 + up, or you can ask Git to fetch differences down from the other repo.
27 + </p>
28 +
29 + <p>You can do this any time you are online, it does not have to correspond
30 + with a <code>commit</code> or anything else. Generally you will do a
31 + number of commits locally, then fetch data from the online shared repository
32 + you cloned the project from to get up to date, merge any new work into the
33 + stuff you did, then push your changes back up.</p>
34 +
35 <p class="nutshell">
36 <b>In a nutshell</b> you can update your project with <code>git fetch</code>
15 - and share your changes with <code>git push</code>.
37 + and share your changes with <code>git push</code>. You can manage your
38 + remote repositories with <code>git remote</code>.
39 + </p>
40 + </div>
41 +</div>
42 +
43 +<div class="box">
44 + <h2>
45 + <span class="docs">
46 + <a target="new" href="http://www.kernel.org/pub/software/scm/git/docs/git-remote.html">docs</a> &nbsp;
47 + <a target="new" href="http://progit.org/book/">book</a>
48 + </span>
49 + <a name="push">git remote</a>
50 + <span class="desc">list, add and delete remote repository aliases</span>
51 + </h2>
52 +
53 + <div class="block">
54 +
55 + <p>Unline centralized version control systems that have a client that is
56 + very different from a server, Git repositories are all basically equal and
57 + you simply syncronize between them. This makes it easy to have more than
58 + one remote repository - you can have some that you have read-only access to
59 + and others that you can write to as well.</p>
60 +
61 + <p>So that you don't have to use the full URL of a remote repository every
62 + time you want to syncronize with it, Git stores an alias or nickname for
63 + each remote repository URL you are interested in. You use the
64 + <code>git remote</code> command to manage this list of remote repos that
65 + you care about.</p>
66 +
67 + <h4>
68 + git remote
69 + <small>list your remote aliases</small>
70 + </h4>
71 +
72 + <p>Without any arguments, Git will simply show you the remote repository
73 + aliases that it has stored. By default, if you cloned the project (as
74 + opposed to creating a new one locally), Git will automatically add the
75 + URL of the repository that you cloned from under the name 'origin'. If
76 + you run the command with the <code>-v</code> option, you can see the
77 + actual URL for each alias.</p>
78 +
79 +<pre>
80 +<b>$ git remote</b>
81 +origin
82 +<b>$ git remote -v</b>
83 +origin git@github.com:schacon/git-reference.git (fetch)
84 +origin git@github.com:schacon/git-reference.git (push)
85 +</pre>
86 +
87 + <p>You see the URL there twice because Git allows you to have different
88 + push and fetch URLs for each remote in case you want to use different
89 + protocols for reads and writes.</p>
90 +
91 + <h4>
92 + git remote add
93 + <small>add a new remote repository of your project</small>
94 + </h4>
95 +
96 + <p>If you want to share a locally created repository, or you want to take
97 + contributions from someone elses repository - if you want to interact in
98 + any way with a new repository, it's generally easiest to add it as a remote.
99 + You do that by running <code>git remote add [alias] [url]</code>. That
100 + adds <code>[url]</code> under a local remote named <code>[alias]</code>.</p>
101 +
102 + <p>For example, if we want to share our Hello World program with the world,
103 + we can create a new repository on a server (I'll use GitHub as an example),
104 + which should give you a URL, in this case "git@github.com:schacon/hw.git".
105 + To add that to our project so we can push to it and fetch updates from it
106 + we would do this:</p>
107 +
108 +<pre>
109 +<b>$ git remote</b>
110 +<b>$ git remote add github git@github.com:schacon/hw.git</b>
111 +<b>$ git remote -v</b>
112 +github git@github.com:schacon/hw.git (fetch)
113 +github git@github.com:schacon/hw.git (push)
114 +</pre>
115 +
116 + <p>Like the branch naming, remote alias names are arbitrary - just as 'master'
117 + has no special meaning but is widely used because <code>git init</code>
118 + sets it up by default, 'origin' is often used as a remote name because
119 + <code>git clone</code> sets it up by default as the cloned-from URL. In
120 + this case I've decided to name my remote 'github', but I could have really
121 + named it just about anything.
122 </p>
123 +
124 + <h4>
125 + git remote rm
126 + <small>removing an existing remote alias</small>
127 + </h4>
128 +
129 + <p>Git addeth and Git taketh away. If you need to remove a remote - you are
130 + not using it anymore, the project is gone, etc - you can remove it with
131 + <code>git remote rm [alias]</code>.</p>
132 +
133 +<pre>
134 +<b>$ git remote -v</b>
135 +github git@github.com:schacon/hw.git (fetch)
136 +github git@github.com:schacon/hw.git (push)
137 +<b>$ git remote add origin git://github.com/pjhyett/hw.git</b>
138 +<b>$ git remote -v</b>
139 +github git@github.com:schacon/hw.git (fetch)
140 +github git@github.com:schacon/hw.git (push)
141 +origin git://github.com/pjhyett/hw.git (fetch)
142 +origin git://github.com/pjhyett/hw.git (push)
143 +<b>$ git remote rm origin</b>
144 +<b>$ git remote -v</b>
145 +github git@github.com:schacon/hw.git (fetch)
146 +github git@github.com:schacon/hw.git (push)
147 +</pre>
148 +
149 + <p class="nutshell">
150 + <b>In a nutshell</b> with <code>git remote</code> you can list our
151 + remote repositories and whatever URL
152 + that repository is using. You can use <code>git remote add</code> to
153 + add new remotes and <code>git remote rm</code> to delete existing ones.
154 + </p>
155 +
156 </div>
157 </div>
158
@@ -37,9 +176,11 @@ layout: reference
176 <a name="pull">git pull</a>
177 <span class="desc">fetch from a remote repo and try to merge into the current branch</span>
178 </h2>
179 +
180 <div class="block">
41 - <p>Cool.</p>
181 + <p>Git has two commands to update itself from a remote repository.</p>
182 </div>
183 +
184 </div>
185
186 <div class="box">