Victor Grazi
Victor Grazi

Reputation: 16510

How can I share a local repository from two different directories on the same PC

I am trying to prepare a Git demo on my Windows laptop, which is off line. Using Git Bash, I created a small project in /c/demo/git-demo/ and did a git init, and added file test.txt and committed it.

Then in another shell, I did

cd /c/demo
git clone /c/demo/git-demo git-demo-clone
cd git-demo-clone
ls -l

That works fine, I see test.txt.

Then I modify the file from git-demo-clone and do a commit, which again works fine.

However when I next do git push from git-demo-clone, I get an error

remote: error: refusing to update checked out branch: refs/heads/master
remote: error: By default, updating the current branch in a non-bare repository
remote: is denied, because it will make the index and work tree inconsistent
remote: with what you pushed, and will require 'git reset --hard' to match
remote: the work tree to HEAD

What to do?

Upvotes: 1

Views: 20

Answers (1)

eftshift0
eftshift0

Reputation: 30277

That happens because in the other repository, the branch that is checked out is the branch you are trying to push (which is normally not ok because it would be like moving someone's rug from under their feet while they are working on a given branch). You could avoid it 4 ways:

  • There's a way to tell git (through repo configuration) to avoid this check (but I don't know the details).
  • Go to the other remote and checkout another branch or set it to be on detached HEAD (git checkout --detach)
  • Push into another branch
  • Instead of pushing into the other repo, go to the other repo, add this remote where you committed as a remote and then pull from it.

Upvotes: 2

Related Questions