When you build a new local directory and would like to copy the whole remote repository content to local, "git clone" should be used. So "git clone" is used after the "git init" of the local directory.
"git pull" will copy the update from the remote repository to local and merge to the current branch.
First, we need add the remote repository:
Then we can "git pull" the contents from the remote repo to local and merge to the current branch:
[root@localhost test01]# git pull origin
test.txt | 7 +++++++
test01.txt | 4 ++++
test05.txt | 1 +
3 files changed, 12 insertions(+)
create mode 100644 test01.txt
create mode 100644 test05.txt
"git fetch" will copy the update in the remote repo to local branch. But it will NOT merge the update to the current branch.
git fetch origin master:tmp
git merge tmp
The above commands will create a new branch call "tmp" and then copy the update to "tmp" branch. Then it merge the "tmp" branch to the master. So "git fetch" will only download the update from the remote repo. But it will not do merge. The "merge" will need to be done manually.
In summary, "git clone" is used after you initialing the local directory for remote repo. "git fetch" will only download the update of the remote repo to local branch but merge will not happen automatically. "git pull" is equal to "git fetch" + "git merge".