diff --git a/remotes/index.html b/remotes/index.html index 57f81b7..d52700a 100644 --- a/remotes/index.html +++ b/remotes/index.html @@ -178,7 +178,75 @@ github git@github.com:schacon/hw.git (push)
Git has two commands to update itself from a remote repository.
+ +Git has two commands to update itself from a remote repository.
+ git fetch
will syncronize you with another repo, pulling down any data
+ that you do not have locally and giving you bookmarks to where each branch on
+ that remote was when you syncronized. These are called "remote branches" and are
+ identical to local branches except that Git will not allow you to check them out -
+ however, you can merge from them, diff them to other branches, run history logs on
+ them, etc. You do all of that stuff locally after you syncronize.
+
The second command that will fetch down new data from a remote server is
+ git pull
. This command will basically run a git fetch
+ immediately follwed by a git merge
of the branch on that remote
+ that is tracked by whatever branch you are currently in. I personally don't much
+ like this command - I prefer running fetch
and merge
+ seperately. Less magic, less problems. However, if you like this idea, you
+ can read about it in more detail in the.
+ official docs.
+
Assuming you have a remote all set up and you want to pull in updates, you
+ would first run git fetch [alias]
to tell Git to fetch down all the
+ data it has that you do not, then you would run git merge [alias]/[branch]
+ to merge into your current branch anything new you see on the server
+ (like if someone else has pushed in the meantime). So, if I were working on my
+ Hello World project with several other people and I wanted to bring in any changes
+ that had been pushed since I last connected, I would do something like this:
+$ git fetch github +remote: Counting objects: 4006, done. +remote: Compressing objects: 100% (1322/1322), done. +remote: Total 2783 (delta 1526), reused 2587 (delta 1387) +Receiving objects: 100% (2783/2783), 1.23 MiB | 10 KiB/s, done. +Resolving deltas: 100% (1526/1526), completed with 387 local objects. +From github.com:schacon/hw + 8e29b09..c7c5a10 master -> github/master + 0709fdc..d4ccf73 c-langs -> github/c-langs + 6684f82..ae06d2b java -> github/java + * [new branch] ada -> github/ada + * [new branch] lisp -> github/lisp ++ +
I can see that since the last time I synchronized with this remote, five branches + have been added or updated. The 'ada' and 'lisp' branches are new, where the + 'master', 'c-langs' and 'java' branches have been updated. In this case, my team + is pushing proposed updates to remote branches for review before they're merged + into 'master'. +
+ +You can see the mapping that Git makes. The 'master' branch on the remote
+ repository becomes a branch named 'github/master' locally. That way now I can
+ merge the 'master' branch on that remote into my local 'master' branch by running
+ git merge github/master
. Or, I can see what new commits are on that
+ branch by running git log github/master ^master
. If your remote
+ is named 'origin' it would be origin/master
instead. Almost any
+ command you would run using local branches you can use remote branches with too.
+
If you have more than one remote repository, you can either fetch from specific
+ ones by running git fetch [alias]
or you can tell Git to syncronize
+ with all of your remotes by running git fetch --all
.
+
+
+ In a nutshell you run git fetch [alias]
to syncronize your
+ repository with a remote repository, fetching all the data it has that you do
+ not into branch references locally for merging and whatnot.
+