What is Git Pull?

Git Pull is a command used to update the local version of a repository from a remote repository. It is a mixture of two other commands:

  • git fetch
  • git merge

In the first stage of operation, git pull will execute a git fetch scoped to the local branch i.e., HEAD ( a reference to the current commit) is pointed at. After the content is downloaded, git pull will do a merge workflow. A new merge commit is created and HEAD is updated and point at the new commit. For example, you create a new repository named Git and push the same file “file.txt”. Now if someone from your team at GitHub made some changes in a file or created some file on a remote repository. Let’s say he or she created a new file “New.txt” but you are not aware of the changes made by him/her.

Now let’s say you have created a new file “crio.txt” (crio means newborn) and after performing a commit when you try to push the file into the remote repository, git will not allow you to push your code because the remote repository contains a task that you do not have locally on your computer.

So, in that case, the git pull command is used to fetch and download content from a remote repository to a local repository. In the below Image, you will see that, after performing git pull origin master, you were able to push the file from your local repository to the remote repository coz the command git pull origin master where the origin is the default repo name and master is the branch updated our local repository up to date from the remote repository.

Merge Conflicts

A merge conflict is an occurrence that happens when Git is unable to auto-resolve, the differences in code between two commits. To resolve merge conflicts use the command:

git mergetool

Leave a Reply

Your email address will not be published. Required fields are marked *