basically finished with remotes sections
Scott Chacon committed
Jun 5, 2010 at 18:54 UTC
e5ef5fea9eb95d0cdbc6fe1a9313f3394bdd6ae0
1 file changed
+75
-1
remotes/index.html
+75
-1
@@ -262,7 +262,81 @@ From github.com:schacon/hw
262
</h2>
263
264
<div class="block">
265
- <p>Cool.</p>
265
+ <p>To share the cool commits you've done with others, you need to push your
266
+ changes to the remote repository. To do this, you run
267
+ <code>git push [alias] [branch]</code> which will attempt to make your [branch]
268
+ the new [branch] on the [alias] remote. Let's try it by initially pushing
269
+ our 'master' branch to the new 'github' remote we created earlier.</p>
270
+
271
+<pre>
272
+<b>$ git push github master</b>
273
+Counting objects: 25, done.
274
+Delta compression using up to 2 threads.
275
+Compressing objects: 100% (25/25), done.
276
+Writing objects: 100% (25/25), 2.43 KiB, done.
277
+Total 25 (delta 4), reused 0 (delta 0)
278
+To git@github.com:schacon/hw.git
279
+ * [new branch] master -> master
280
+</pre>
281
+
282
+ <p>Pretty easy. Now if someone clones that repository they will get exactly
283
+ what I have committed and all of it's history.</p>
284
+
285
+ <p>What if I have a topic branch like the 'erlang' branch we created earlier
286
+ and I just want to share that? You can just push that branch instead.
287
+
288
+<pre>
289
+<b>$ git push github erlang</b>
290
+Counting objects: 7, done.
291
+Delta compression using up to 2 threads.
292
+Compressing objects: 100% (6/6), done.
293
+Writing objects: 100% (6/6), 652 bytes, done.
294
+Total 6 (delta 1), reused 0 (delta 0)
295
+To git@github.com:schacon/hw.git
296
+ * [new branch] erlang -> erlang
297
+</pre>
298
+
299
+ <p>Now when people clone or fetch from that repository, they'll get a 'erlang'
300
+ branch they can look at and merge from. You can push any branch to any
301
+ remote repository that you have write access to in this way. If your branch
302
+ is already on the server, it will try to update it, if it is not, Git will
303
+ add it.</p>
304
+
305
+ <p>The last major issue you run into with pushing to remote branches is the
306
+ case of someone pushing in the meantime. If you and another developer clone
307
+ at the same time, you both do commits, then she pushes and then you try to
308
+ push, Git will by default not allow you to overwrite her changes. Instead,
309
+ it basically runs <code>git log</code> on the branch you're trying to push and
310
+ makes sure it can see the current tip of the servers branch in your pushes
311
+ history. If it can't see what is on the server in your history, it concludes
312
+ that you are out of date and will reject your push. You will rightly have to
313
+ fetch, merge then push again - which makes sure you take her changes into
314
+ account.</p>
315
+
316
+ <p>This is what happens when you try to push a branch to a remote branch
317
+ that has been updated in the meantime:</p>
318
+
319
+<pre>
320
+<b>$ git push github master</b>
321
+To git@github.com:schacon/hw.git
322
+ ! [rejected] master -> master (non-fast-forward)
323
+error: failed to push some refs to 'git@github.com:schacon/hw.git'
324
+To prevent you from losing history, non-fast-forward updates were rejected
325
+Merge the remote changes before pushing again. See the 'Note about
326
+fast-forwards' section of 'git push --help' for details.
327
+</pre>
328
+
329
+ <p>You can fix this by running <code>git fetch github; git merge github/master</code>
330
+ and then pushing again.
331
+
332
+ <p class="nutshell">
333
+ <b>In a nutshell</b> you run <code>git push [alias] [branch]</code> to update a
334
+ remote repository with the changes you've made locally. It will take what your
335
+ [branch] looks like and push it to be [branch] on the remote, if possible. If
336
+ someone else has pushed since you last fetched and merged, the Git server will
337
+ deny your push until you are up to date.
338
+ </p>
339
+
340
</div>
341
</div>
342