`git init –bare`: to create a new git repository from an existing one (via: Stack Overflow)
Posted by jpluimers on 2015/06/23
I needed to get an existing Git repository to a client that had a tightened network. No SSH allowed, web proxy filtering out all sorts of sites and also performing a HTTPS man-in-the-middle to detect and reject all kinds of binaries, etc.
But we needed a public repository locally.
Which worked, thanks to pestrella, who answered about `bare` repositories to get my last steps correct:
In order to create a new Git repository from an existing repository one would typically create a new bare repository and push one or more branches from the existing to the new repository.
The trick is to know that server-side repositories are `bare` and client side repositories are `regular`. `bare` means the absence of a working copy on the server side.
I performed these steps:
- git clone https://path-to/public/repository local-clone
- 7zip compressed the local-clone directory tree and contents recursively into a 7z file
- RC4 the 7z into an opaque binary
- Put the binary on-line
- Downloaded the RC4ed binary (so the web proxy would not find out what it was)
- RC4 the binary back to 7z
- Uncompressed the 7z file into a local-clone directory tree
- Created a new shared-repository.git directory
- CD-ed into that
- Created a bare repository: `git init-bare`
- Pushed the local-clone master branch into the new bare repository: git push file:///X:\path-to\shared-repository.git master
No need for `+topic1:master` although that would have worked just as well.
References on `bare` repositories:
- Git bare vs. non-bare repositories.
- What is a bare git repository? | Jon Saints.
- Git – Getting Git on a Server.
If you forget --bare, then you get an error while performing the push:
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: error: is denied, because it will make the index and work tree inconsistent
remote: error: with what you pushed, and will require 'git reset --hard' to match
remote: error: the work tree to HEAD.
remote: error:
remote: error: You can set 'receive.denyCurrentBranch' configuration variable to
remote: error: 'ignore' or 'warn' in the remote repository to allow pushing into
remote: error: its current branch; however, this is not recommended unless you
remote: error: arranged to update its work tree to match what you pushed in some
remote: error: other way.
remote: error:
remote: error: To squelch this message and still keep the default behaviour, set
remote: error: 'receive.denyCurrentBranch' configuration variable to 'refuse'.
–jeroen
via: how to create a new git repository from an existing one – Stack Overflow.






Leave a comment