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.

8
  • 1
    What's the purpose of the bare repo?
    – chepner
    Commented Aug 29, 2018 at 17:12
  • Its a long story and I don't think its relevant. The question is, can git do this?
    – chuck1
    Commented Aug 29, 2018 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
    Commented Aug 29, 2018 at 17:19
  • @chepner OK I've added what I've tried so far to my question
    – chuck1
    Commented Aug 29, 2018 at 17:26
  • Unless bare_repo is inside another repository, that git remote command shouldn't even work.
    – chepner
    Commented Aug 29, 2018 at 17:41

1 Answer 1

2

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

2
  • 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
    Commented Aug 29, 2018 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
    Commented Aug 29, 2018 at 19:06

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