Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'm having trouble pushing my code to a git remote repository from my localhost. This problem only appears for repositories that were initially created with remote urls that are system directories (eg. /var/www/lib) and later accessed via remote urls that are http urls (eg. http://mysite.com/repo.git). Here's the error I'm getting:

Fetching remote heads...
  refs/
  refs/tags/
  refs/heads/
  fetch 023264fe3e5e24075307512502599d279c1a1640 for refs/heads/master
error: remote 'refs/heads/master' is not an ancestor of
local 'refs/heads/master'.
Maybe you are not up-to-date and need to pull first?
fatal: git-http-push failed

Here are the steps to creating the problem. Initially, I populated the remote bare repository from the remote server itself like so:

cd /var/www/
git init
git add .
git commit -m 'test'
git remote add newproject /var/lib/git/newproject.git  ## I suspect the problem begins here
git push newproject master

For about a week, I've been committing, pulling and pushing without problems because I was working directly off of the remote server from /var/www/. Then today, I installed webdav so that I can push and pull from my local host. I'm pretty sure I installed and configured git and apache properly. So from my localhost, here's what I did:

cd /home/user/newproject/
git init
git remote add newproject http://www-data@website.com/newproject.git  # this is different from above where i used /var/lib/git/newproject
git pull newproject master   #worked perfectly
vi test.html
git add test.html
git commit -m 'test'
git push newproject master

Then I get the error as first mentioned. A pull did not fix this problem. All new repositories made with the http versions have no problem with push and pull. Only old repositories that were first made with /var/lib/git are having problems when switching to the http version.

Does anyone know how to fix this?

share|improve this question

1 Answer 1

I take from your question, that webdav for the same user works as intended for other repositories, so webdav is configured correctly.

Where does http://www-data@website.com/newproject.git point to? Does it point to the repo at /var/lib/git/newproject.git or to /var/www?

I can see two potential problems:

  1. The httpd user needs write access to all repo files
  2. The repository should be bare

Write access for the httpd user

Does the webserver have write access to all parts of the repository? When you pushed locally, you might have created files with a user account (or root) that the webserver can't write now. Obviously the same applies when the webserver tries to access the repo at /var/www.

The best option would be to chown -R all files to the httpd user.

Bare repo

Is the destination repo a bare repo?

It is technically not necessary for the repo to be bare, but there are issues that can arise when you have a checked out working copy of a branch you are pushing to. Your problem might be one of these issues.

See also how-to-convert-a-git-repository-from-normal-to-bare and all about "bare" repos.

You should check git status, git branch and similar in the destination directory for problems.


If you keep having issues, another obvious option is to clone the served repo, move the served repo to some other place, git init --bare (fix permissions or do it as httpd user) and push again.


problem-with-git-remote-refs-heads-master-is-not-an-ancestor-of-local-refs-h is a question on Stackoverflow about the same error message on a similar setup.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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