1

I am trying to use a bare git repo as a bridge between my working repo and the origin

origin ----- bare repo ----- working repo

I can go into the working repo and push and pull from the bare repo. But I also need to go into the bare repo and push and pull form the origin, is that possible?

EDIT

What I've tried so far...

To create the bare repo

mkdir bare_repo
cd bare_repo
git init --bare
git remote add origin path_to_origin
git fetch origin

To create the working repo

git clone path_to_bare

I get a warning: "remote HEAD refers to nonexistant ref, unable to checkout", but it still creates the working repo

git pull origin master

I get an error: "Couldnt find remote ref master"

UPDATE

Turns out I had a write permissions issue, and so I couldn't push from the working repo to the bare repo. So I general I need to check permissions for all my repo locations before asking questions... Now everything is working...

One things is, if someone else pushes a commit to the origin, I will need to fetch that commit from my bare repo and update the branch on my bare repo. The fetch is simple enough

# in bare repo
git fetch origin master

but I dont know the best way to update the branch. I cant pull because there is no working directory. I can get the hash of the new commit using

git ls-remote

and then manually point the branch to it with

git branch -f master <hash>

But it seems like there would be a better way.

But I think that should be a separate question.

chuck1
  • 665
  • 7
  • 22
  • 1
    What's the purpose of the bare repo? – chepner Aug 29 '18 at 17:12
  • Its a long story and I don't think its relevant. The question is, can git do this? – chuck1 Aug 29 '18 at 17:14
  • Have you tried anything? For a push or pull operation, you don't need a working directory, so there shouldn't be any difference between the bare repo and your working repo in this case. – chepner Aug 29 '18 at 17:19
  • @chepner OK I've added what I've tried so far to my question – chuck1 Aug 29 '18 at 17:26
  • Unless `bare_repo` is inside another repository, that `git remote` command shouldn't even work. – chepner Aug 29 '18 at 17:41
  • My bad, I forgot the "git init --bare" line – chuck1 Aug 29 '18 at 17:45
  • @chuck1 I know you said it's a long story, but it probably is relevant. There's probably a better way to solve whatever you're solving with the middle bare repo. Perhaps with an ssh tunnel? – Schwern Aug 29 '18 at 18:00
  • @Schwern I agree with you that there is probably a better solution to my underlying issue. But this is a question about what git is capable of and how to use it. – chuck1 Aug 29 '18 at 18:04

1 Answers1

2

You can clone the original repo as a bare repo with: git clone --bare <repo url>

nnyby
  • 4,748
  • 10
  • 49
  • 105
  • Tried this. When I try to push a new commit from the working repo to the bare repo, I get: "remote unpack failed: unable to create temporary object directory" – chuck1 Aug 29 '18 at 17:40
  • Actually this does work, see my update. You can also create an empty bare repo and add the remote manually though. – chuck1 Aug 29 '18 at 19:06