Git - git pull


What is the purpose of the 'git pull' command?

Suppose that Alice has started a new project with a Git repository in /home/alice/project, and that Bob, who has a home directory on the same machine, wants to contribute. Bob begins with:

git clone /home/alice/project myrepo

This creates a new directory "myrepo" containing a clone of Alice’s repository. The clone is on an equal footing with the original project, possessing its own copy of the original project’s history. Bob then makes some changes and commits them:

git commit -a

When he’s ready, he tells Alice to pull changes from the repository at /home/bob/myrepo. She does this with:

cd /home/alice/project
git pull /home/bob/myrepo master

This merges the changes from Bob’s "master" branch into Alice’s current branch. If Alice has made her own changes in the meantime, then she may need to manually fix any conflicts. The "pull" command thus performs two operations: it fetches changes from a remote branch, then merges them into the current branch.

Note that in general, Alice would want her local changes committed before initiating this "pull". If Bob’s work conflicts with what Alice did since their histories forked, Alice will use her working tree and the index to resolve conflicts, and existing local changes will interfere with the conflict resolution process (Git will still perform the fetch but will refuse to merge —- Alice will have to get rid of her local changes in some way and pull again when this happens).

Why do we sometimes have to use 'git pull' with a full URL and sometimes we can omit the URL?

When Bob cloned Alice’s repository, Git stored the location of her repository in the repository configuration, and that location is used for pulls:

git pull

To display the remote URL:

git config --get remote.origin.url

The complete configuration created by git clone is visible using:

git config -l

How can we merge changes from a remote machine?

git pull git://foo/repo.git/ branch
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License