19

We use Github for source control in our organization. Multiple developers continuously merge their changes to remote source repository. In my case I cloned the repository when two weeks back and there were multiple merges after that. Now I am trying to get the latest revision of the code using.

git pull origin master

I for sure know that there were multiple merges that have gone in since last time I cloned but pull command tells me that its already up to date. Am I missing anything here?

4
  • Is git fetch showing anything?
    – Nic
    Commented Nov 12, 2012 at 3:45
  • @Nic It didn't give me anything .. it just asked for credentials
    – Ram
    Commented Nov 12, 2012 at 7:26
  • try a git reset --hard origin master , may be your local head is not on the good index Commented Feb 9, 2016 at 10:05
  • git reset --hard origin master gives fatal: Cannot do hard reset with paths.. Commented Jul 14 at 19:24

7 Answers 7

22
git reset --hard HEAD~20 # some large number
git pull origin master

This fixed my problem with an un-pullable update. The idea is to push HEAD back far enough to clear up any confusion for git. Then make the desired pull.

1
  • 1
    How about resolving this?
    – joel3000
    Commented Sep 10, 2021 at 17:43
5

For me the solution was:

from the current branch I executed git pull origin ${current-branch-name} in my specific case the complete command was:

From develop branch: git pull origin develop

The git reset --hard HEAD and git pull origin HEAD commands do not work for me.

3
  • 1
    This solved the issue for me where the reset did not. Thanks for that. Commented May 14, 2023 at 9:19
  • This worked for me! I was having issues in one of my branches where I cannot pull the latest commit. I switched to a different branch and pulled using the suggested code above and it worked!
    – user12401635
    Commented Sep 11, 2023 at 22:48
  • This worked for me whereas the other suggestions did not. Wondering what might have caused this scenario, as this kept happening lately. I suspect it has to do with what other people are doing at the repository (minimal experience and communication)
    – ltree
    Commented Jan 30 at 14:56
3

One explanation would be that the latest commits have been done on another branch, as explained in "Git pull from my public repository not working".

The other possibility is for you to be in a detached HEAD mode.
That would make any git pull "up-to-date" since you are in any branch.

1

I used Team Explorer from my Visual Studio application and was able to Sync, Fetch, and Pull. That finally worked.

1

For me, nothing seemed to work and I had to clone the repository from GitHub again. As a last resort that might be an option.

1
  • If all other things fail, you can avoid needing to clone the entire repo by going to a different branch, deleting the problematic one, running git fetch and then changing back to it. Commented May 14, 2023 at 9:21
0

I used git status to show all the current local changes to files. I then removed them by using the command "git restore <file>...". After removing all I simply used git pull origin/master and it fixed the issue.

0

So there are some unpopular realities:

  1. Git does have errors that place it into unknowable states. Some of these states are recoverable, some are not.

  2. Git has options that place you into obscure states, such as detaching your head, applying commits to different branches locally and remotely. These are usually recoverable with more arcane tricks.

  3. Git is a program with an open source license. GitHub is a proprietary website owned by MicroSoft. One will expect some bundling issues, meaning GitHub will work differently on Microsoft Windows or other Microsoft products. The goal of GitHub is not "best developer experience".

  4. The Git experience is convoluted and opaque. For example, contributing to a project usually requires this little dance:

  • making a fork of the project,
  • clone your fork of the project,
  • making your own branch in that project,
  • write the changes,
  • commit the changes locally,
  • push the changes to your branch of the your repository
  • create a pull request in the main project
  • switch your local branch to prevent future changes from automatically being added to the pull request
  1. You will need to check the configurations of your ~/.gitconfig and project .git/config.

Given that:

  1. Check that you are on the main branch, usually named master or main and that your head is not detached. Do this with git status.

  2. Check that your configuration even knows about the repository you are trying to pull from, instead of just your own fork of the repository. Do this with "cat <project_directory>.git/config". You may be trying to pull from the open source project, but only pulling from your own, now out of date, fork of the repository.

  3. Try one or two tricks for a broken repository. As @joel3000 suggests, move your head (lastest commit you see) back in time to try to force commits to be reloaded and reapplied. That is done as git reset --hard HEAD~90 && git pull origin HEAD. Maybe it works, maybe it doesn't.

  4. Give up; chalk it up the cost of a proprietary system. Try deleting and reloading things.

  • First, save any work locally to a new directory
  • Second, delete your local repository and git clone a new copy from the main open source project.
  • Third, if that doesn't work, delete your GitHub fork and recreate it.

There is a significant cost to using the git/Github lifecycle.

Not the answer you're looking for? Browse other questions tagged or ask your own question.