4

There is a Git repository proj.git, cloned to proj1 and proj2. proj1 has no worktree, proj2 has a worktree.

The goal: update a.txt in proj1, get the change updated to worktree in proj2.

The problem: git pull fails on proj2 with an error message:

fatal: Not a git repository (or any of the parent directories): .git

Reproducing the problem:

Create proj.git and proj1:

$ git init --bare proj.git
$ git clone proj.git proj1
$ cd proj1
- edit a.txt: v1
$ git add .
$ git commit -m "v1"
$ git push -u origin master

Create proj2 with worktree:

 $ cd ..
 $ git clone -n proj.git proj2
 $ mkdir proj2_worktree
 $ cd proj2
 - edit .git/config:
   [core]
       ...
       worktree = /path/to/workarea/proj2_worktree
 $ git checkout

proj2_worktree contains a.txt, works as expected.

Check the status of origin in proj2:

 $ git remote show origin
 * remote origin
   Fetch URL: /path/to/workarea/proj.git
   Push  URL: /path/to/workarea/proj.git
   HEAD branch: master
   Remote branch:
     master tracked
   Local branch configured for 'git pull':
     master merges with remote master
   Local ref configured for 'git push':
     master pushes to master (up to date)

Try to pull-in changes in proj2 (that does have .git):

 $ git pull
 fatal: Not a git repository (or any of the parent directories): .git
 fatal: Not a git repository (or any of the parent directories): .git
 fatal: Not a git repository (or any of the parent directories): .git
 fatal: Not a git repository (or any of the parent directories): .git

 $ git init
 Reinitialized existing Git repository in /path/to/workarea/proj2/.git/

 $ git pull
 fatal: Not a git repository (or any of the parent directories): .git
 fatal: Not a git repository (or any of the parent directories): .git
 fatal: Not a git repository (or any of the parent directories): .git
 fatal: Not a git repository (or any of the parent directories): .git

What am I doing wrong? My Git versions are 1.7.10.4 on Debian / 2.1.1 on Cygwin.

EDIT:

An additional finding: In proj2, the usual fetch/merge will work as a workaround to the problem:

$ git fetch
$ git merge origin master

BUT: still, why does pull not work?

masa
  • 2,762
  • 3
  • 21
  • 32
  • Why do u use --bare? bare means no working directory – CodeWizard Feb 15 '15 at 10:55
  • 1
    `proj.git` is a central repository. Typically, those repositories are kept bare. – masa Feb 15 '15 at 12:26
  • Where are you when you execute `git pull` for proj2? In `/path/to/workarea/proj2`, or in `/path/to/workarea/proj2_worktree`? Does it work if you use `git --git-dir /path/to/workarea/proj2 pull`? – poke Feb 15 '15 at 15:18
  • 1
    @poke: `git pull` in `proj2` does not work, but `git --git-dir /path/to/workarea/proj2/.git pull` in `proj2_worktree` works ok. Notice that `git fetch` works in `proj2`, it is only `pull` that does not work. – masa Feb 15 '15 at 15:47

1 Answers1

2

Setting core.worktree in .git/config is usually a bad idea since it will cause a lot of confusion unless you know exactly what’s going on.

If your plan is to deploy a revision of the repository at /path/to/workarea/proj2_worktree without having a .git folder inside (which makes sense for deployments), then I’d suggest you to use a more explicit checkout, directly from the bare repository:

git --git-dir=/path/to/proj.git --worktree=/path/to/worktree checkout master

(or execute the command from within proj.git, so you don’t need to specify --git-dir)


As for your actual problem, this might be a bug with an earlier version of Git. I’ve found some other questions that refer to this, so if my suggestion above does not fit your need, I’d advise you to update your Git version. After all, 1.7.10.4 is almost three years old.

Community
  • 1
  • 1
poke
  • 369,085
  • 72
  • 557
  • 602
  • 1
    Thanks! This is a deployment, but I need to be able to push updates from the deployment directory to the central repository, so I need to have a non-bare repository in-between? What comes to your latter proposal, the behaviour is the same in Git v.2.3.0. I would be curious to know, what is the correct method for setting up the worktree, if editing `core.worktree` is a bad idea. There is very little documentation on the topic. However, I guess `fetch`/`merge` will do just fine. – masa Feb 15 '15 at 16:36