by BehindJava

What is git clone, git fetch and git pull in GIT

Home » interview » What is git clone, git fetch and git pull in GIT

In this tutorial, we are going to learn about git clone, git fetch and git pull in detail where git clone is used to download the entire remote git repository into the local machine. This works only when the code present in the remote server is different from that in the local repository. git fetch will download only the modified files and it will place them on a separate branch called as “remote branch”.

git clone

This is used to download the entire remote git repository into the local machine.This is generally used only one time when all the team members want a copy of the code present in the git remote server.

git clone remote_git_hub_url

git fetch:

This will work only when the code present in the remote server is different from the code present in the local repository git fetch will download only the modified files and it will place them on a separate branch which is called as “remote branch”.

  • We can go to this remote branch and check if the modifications are acceptable, if so we can merge them with the master branch.
  • Open github.com.
  • Click on the repository that we updated.
  • Select a file to be modified and click on Edit icon.
  • Make some changes and click on commit changes.
  • Open git bash.

    git fetch
  • This will download all the modified files and place them on a.

    remote branch
  • To see the list of all the branches.

    git branch -a
  • Move into the remote branch.

    git checkout remote_branch_name_from_step8
  • Check if the modifications are acceptable if so move to master and merge.

    git checkout master
    git merge remote_branch_name_from_step8

git pull

This will also download only the modified files but it will merge them with the master.

  1. Open github.com.
  2. Click on the repository that we updated.
  3. Select a file to be modified and click on Edit icon.
  4. Make some changes and click on commit changes.
  5. Open git bash.

    git pull

    We will be able to see the modified files directly on the master.