Git Pull Not Updating Files

John Wachira Mar 24, 2022
  1. git pull Not Updating Files Due to Missing Information
  2. git pull Not Updating Files Due to Uncommitted Files in Your Local Repository
Git Pull Not Updating Files

This article will discuss why the git pull command can fail to update the files in your local repository with the files from your remote repository.

The git pull function can malfunction due to several reasons. We will look at the frequent reasons and how you can remedy them.

git pull Not Updating Files Due to Missing Information

When Git does not have enough information to work with, you may get an error message, like the one below.

$ git pull
There is no tracking information for the current branch.
Please specify which branch you want to merge with.
See git-pull(1) for details.
    git pull <remote> <branch>
If you wish to set tracking information for this branch you can do so with:
    git branch --set-upstream-to=<remote>/<branch> master

If you get such a message, Git will require you to specify the remote branch to track with your current local branch. Use the git branch --set-upstream-to=<remote>/<branch> master command and then run the git pull command to point Git to where you want the changes to come from.

git pull Not Updating Files Due to Uncommitted Files in Your Local Repository

As a source code management system, Git does its best to prevent you from losing your files and data. For this reason, Git may refuse to merge your local files with files from your remote repository when performing the git pull command.

Since Git does not have a forced git pull command, you can invoke the system to merge the changes. If you have uncommitted changes, you will likely get an error message like the one shown below.

$ git pull
From REPOSITORY_URL
 * branch            master     -> FETCH_HEAD
   a152b19..171e4a2  master     -> origin/master
Updating a152b19..171e4a2
error: Your local changes to the following files would be overwritten by merge:
  file1.txt
  file2.txt
Please commit your changes or stash them before you merge.
Aborting

To remedy this, run the git stash command to stash your local changes before running the git pull command.

The last step is to run the git stash apply after the git pull command. This command will apply the stashed changes to your working directory.

$ git stash
Saved working directory and index state WIP on master: d91368b Previous commit message
$ git pull
From REPOSITORY_URL
 * branch            master     -> FETCH_HEAD
   a152b19..171e4a2  master     -> origin/master
Updating a152b19..171e4a2
Fast-forward
 file1.txt | 1 +
 file2.txt | 1 +
 2 files changed, 2 insertions(++)
$ git stash apply

You can also commit the changes before running the git pull command.

$ git commit -am 'Committing two files before git-pull'
[master d91368b] Committing two files before git-pull
 2 files changed, 2 insertions(++)
$ git pull
From REPOSITORY_URL
 * branch            master     -> FETCH_HEAD
   a152b19..171e4a2  master     -> origin/master
Updating a152b19..171e4a2
Fast-forward
 file1.txt | 1 +
 file2.txt | 1 +
 2 files changed, 2 insertions(++)

If you don’t need the local changes, you can discard them before running the git pull command.

You can use the git rest --hard command and the git clean -fd command to discard untracked files. Be sure you do not need these changes as you cannot reverse a discard.

Author: John Wachira
John Wachira avatar John Wachira avatar

John is a Git and PowerShell geek. He uses his expertise in the version control system to help businesses manage their source code. According to him, Shell scripting is the number one choice for automating the management of systems.

LinkedIn