Pull - biswajitsundara/gitdoc GitHub Wiki

Git pull command downloads content from a remote repository and immediately merges to the local repository to match that content.

  • git pull is equivalent to running both git fetch and git merge in a single command.
  • When we run git pull, it will first download any new changes from the remote repository and update your local copies of the remote-tracking branches.
  • It will then automatically merge the fetched changes into the current local branch.

Example

  • If we are on the master branch and run git pull, Git will fetch the latest changes from the remote master branch and merge them into our local master branch.
  • If there are any merge conflicts, it will prompt you to resolve them before the merge can be completed.

Workflow

  1. Be on the branch we want to update with remote
git branch
*master
  1. Run the git pull command
git pull 
or
git pull origin master
  • This will download any new changes from the remote master branch and merge them into your current local branch.
  • If there are any conflicts, Git will prompt you to resolve them before the merge can be completed.
  • This is the convenient way to quickly update the local repository with the latest changes from the remote repository
  • but it's important to be mindful of any potential conflicts that may arise.

Difference between Fetch and Pull

  • Both the commands git fetch & git pull are used to download the contents from remote and update local branches
  • Git fetch will download and update the remote tracking branches in the local but it won't merge automatically
  • However Git pull will download and update the remote tracking branches and merge the code to the current branch automatically.
  • Git pull = Git Fetch + Git Merge

Pull the remote master branch

Pull the remote master branch and automatically accept all incoming changes from the remote branch in case of conflicts

  • This will pull the latest changes from the remote master branch and automatically accept all incoming changes from the remote branch in case of conflicts, without prompting you to manually resolve them.
  • Note that this command will overwrite any local changes that conflict with the incoming changes from the remote master branch, so make sure to commit any local changes before running this command if you want to preserve them.
  • If we want to discard the remote master branch's updates and retain out=r local changes then instead of theirs we can use ours
  1. Be on the master branch
git checkout master
  1. Run the git pull command with option -x
git pull -X theirs origin master