Skip to content

Commit fcbb818

Browse files
committed
more or less done with fetch/pull
1 parent f922c71 commit fcbb818

File tree

1 file changed

+69
-1
lines changed

1 file changed

+69
-1
lines changed

remotes/index.html

Lines changed: 69 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,75 @@ <h2>
178178
</h2>
179179

180180
<div class="block">
181-
<p>Git has two commands to update itself from a remote repository.</p>
181+
182+
<p>Git has two commands to update itself from a remote repository.
183+
<code>git fetch</code> will syncronize you with another repo, pulling down any data
184+
that you do not have locally and giving you bookmarks to where each branch on
185+
that remote was when you syncronized. These are called "remote branches" and are
186+
identical to local branches except that Git will not allow you to check them out -
187+
however, you can merge from them, diff them to other branches, run history logs on
188+
them, etc. You do all of that stuff locally after you syncronize.
189+
</p>
190+
191+
<p>The second command that will fetch down new data from a remote server is
192+
<code>git pull</code>. This command will basically run a <code>git fetch</code>
193+
immediately follwed by a <code>git merge</code> of the branch on that remote
194+
that is tracked by whatever branch you are currently in. I personally don't much
195+
like this command - I prefer running <code>fetch</code> and <code>merge</code>
196+
seperately. Less magic, less problems. However, if you like this idea, you
197+
can read about it in more detail in the.
198+
<a target="new" href="http://www.kernel.org/pub/software/scm/git/docs/git-pull.html">official docs</a>.
199+
</p>
200+
201+
<p>Assuming you have a remote all set up and you want to pull in updates, you
202+
would first run <code>git fetch [alias]</code> to tell Git to fetch down all the
203+
data it has that you do not, then you would run <code>git merge [alias]/[branch]</code>
204+
to merge into your current branch anything new you see on the server
205+
(like if someone else has pushed in the meantime). So, if I were working on my
206+
Hello World project with several other people and I wanted to bring in any changes
207+
that had been pushed since I last connected, I would do something like this:</p>
208+
209+
<pre>
210+
<b>$ git fetch github</b>
211+
remote: Counting objects: 4006, done.
212+
remote: Compressing objects: 100% (1322/1322), done.
213+
remote: Total 2783 (delta 1526), reused 2587 (delta 1387)
214+
Receiving objects: 100% (2783/2783), 1.23 MiB | 10 KiB/s, done.
215+
Resolving deltas: 100% (1526/1526), completed with 387 local objects.
216+
From github.com:schacon/hw
217+
8e29b09..c7c5a10 master -> github/master
218+
0709fdc..d4ccf73 c-langs -> github/c-langs
219+
6684f82..ae06d2b java -> github/java
220+
* [new branch] ada -> github/ada
221+
* [new branch] lisp -> github/lisp
222+
</pre>
223+
224+
<p>I can see that since the last time I synchronized with this remote, five branches
225+
have been added or updated. The 'ada' and 'lisp' branches are new, where the
226+
'master', 'c-langs' and 'java' branches have been updated. In this case, my team
227+
is pushing proposed updates to remote branches for review before they're merged
228+
into 'master'.
229+
</p>
230+
231+
<p>You can see the mapping that Git makes. The 'master' branch on the remote
232+
repository becomes a branch named 'github/master' locally. That way now I can
233+
merge the 'master' branch on that remote into my local 'master' branch by running
234+
<code>git merge github/master</code>. Or, I can see what new commits are on that
235+
branch by running <code>git log github/master ^master</code>. If your remote
236+
is named 'origin' it would be <code>origin/master</code> instead. Almost any
237+
command you would run using local branches you can use remote branches with too.
238+
</p>
239+
240+
<p>If you have more than one remote repository, you can either fetch from specific
241+
ones by running <code>git fetch [alias]</code> or you can tell Git to syncronize
242+
with all of your remotes by running <code>git fetch --all</code>.
243+
244+
<p class="nutshell">
245+
<b>In a nutshell</b> you run <code>git fetch [alias]</code> to syncronize your
246+
repository with a remote repository, fetching all the data it has that you do
247+
not into branch references locally for merging and whatnot.
248+
</p>
249+
182250
</div>
183251

184252
</div>

0 commit comments

Comments
 (0)