0

It seems like the central git repo I'm working with is both non-bare and has no working tree, which doesn't seem possible given my understanding of the definition of non-bare.

In the repository the result of git rev-parse --is-bare-repository is false

And when I look at its branch list the master branch is shown as checked-out with an asterisk.

However when I try to checkout a different branch I am met with:

fatal: This operation must be run in a work tree

I discovered this when I tried to push my changes from my local repo and got:

! [remote rejected] master -> master (branch is currently checked out)

Could someone help me understand the situation more? Ideally I would want the central repo to be bare and to be able to push there.

For context, I did not create the repo myself so I'm not sure if this is purposeful or happened by accident somehow.

Edit: For more info, here is the content of the config file

[core]
        repositoryformatversion = 0
        filemode = true
        bare = false
[receive]
        denyCurrentBranch = refuse
  • I'd double-check the URL first as everything *except* that `remote rejected` error makes sense: a bare repository has a `HEAD` but that `HEAD` is not actually checked out, by definition. – torek Jun 04 '20 at 20:46
  • Do you mean the remote URL? I ran ' git remote -v' in my local repo and the URLs look as expected, though I'm not sure what I'm looking for. – IfIhadANickel222 Jun 05 '20 at 12:21
  • I may have misread your question. There must be at least two repositories involved here, one on the server and one on your own system. In general, the server repository *should* be bare, i.e., have `core.bare` set to `true`, and there should generally be no `[receive]` section at all. Your own local repository should *not* be bare, i.e., should have `core.bare` set to `false`. Probably the URL (use `git remote -v` on your client-side local repository to check) is correct and these odd server settings are at fault. – torek Jun 05 '20 at 20:04
  • It's not at all clear why your server side repository is set up this strange way. – torek Jun 05 '20 at 20:05

1 Answers1

0

The bare value comes from the .git/config file. This is set to true automatically, when initializing a repository with git init --bare.

If that's not the case, the option can be set manually later:

git config core.bare true
knittl
  • 246,190
  • 53
  • 318
  • 364
  • Thank you that command may solve it, but I am mainly looking for an explanation of how/why my repo came to be in this state – IfIhadANickel222 Jun 05 '20 at 12:42
  • Well, somebody might have created a "regular" Git repository and then only copied the `.git` folder to a server. Or created a regular Git repository on the server, noticed the mistake, deleted the working tree but left the `.git` repository untouched. I guess that question will remain unanswered – knittl Jun 05 '20 at 21:52