Why is git pull not working?

There are several causes for a malfunctioning git-pull command. We'll do our best to mention the most frequent below:

1. Not enough information for Git to work with

$ 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

As the error message states: you will have to let Git know what remote branch it should use to track with the current local branch. Doing this will allow you to simply run git pull and Git will know where to bring new data from.

2. Git pull would overwrite uncommitted files in your local repository

Git is doing its best to prevent you from losing data. As such, at times, it will simply prevent a git pull command from merging new data fetched from the server with your local branch.

$ 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

The message received from Git is a good starting point. The two files have been modified locally, and the new data fetched from the remote cannot be automatically merged by Git. As such, our intervention is required:

  • You may try to commit the changes first and then run git pull again:
  • $ 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(++)
  • You may try to stash your local changes, pull from the remote, and then apply the stashed changes:
  • $ 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

For a complete list of all options for git-pull check the official Git docs: https://git-scm.com/docs/git-pull.