Getting a working copy of a bare repository

前端 未结 7 700
渐次进展
渐次进展 2020-12-08 09:35

I have a server on which I have a bare repository for pushing. However, my server needs to have a working copy of the master branch.

How do I get a working copy and

相关标签:
7条回答
  • 2020-12-08 10:03

    A bare repository is just the .git directory of a working directory, and an entry in the local config file. What I did to convert a bare repository into a full one is:

    • Create a new subdirectory .git and move all files from the bare repository in there
    • Edit the .git/config file to change bare = true to bare = false
    • Check out the branch you want. This extracts all files from the repository into the working directory.

    You could set the Hidden attribute on the .git directory on Windows, but not on the files inside the directory.

    0 讨论(0)
  • 2020-12-08 10:04

    I was looking for the "detached working tree" approach (as seen here):

    git init --bare
    
    git config core.bare false
    git config core.worktree /somewhere/else/
    
    git checkout -f
    
    0 讨论(0)
  • 2020-12-08 10:15

    You can use 'git show' for this.

    http://www.kernel.org/pub/software/scm/git/docs/git-show.html

    Basically:

    git --no-pager --git-dir /path/to/bar/repo.git show branch:path/to/file.txt
    
    0 讨论(0)
  • 2020-12-08 10:17

    You can simply clone the repository to another directory on the same machine:

    git clone /bare/repo/dir
    

    The current directory will become a non-bare clone of your repo, and you'll get a checkout of the master branch automatically. Then use the usual commands like git pull to update it as needed.

    As a side benefit, this operation is very efficient — if you specify a local directory to git clone, git will use hard links to share the read-only parts of the object databases of the two repos.

    0 讨论(0)
  • 2020-12-08 10:18

    This is a riff off the other 2 answers but it fills the gap for my use case -- it works for updating the repo from the origin and checking out branches and any git operation because you end up with a normal complete git repo.

    git clone /path/to/bare/repo /new/path/to/full/repo
    cd /new/path/to/full/repo
    git remote set-url origin git@github.com:swift/swift.git
    

    After executing these 3 lines of code you can then git pull and git branch and git checkout some_branch and so on because you now have a normal complete git repo connected to your remote repo.

    0 讨论(0)
  • 2020-12-08 10:25

    This is how it works:

    $ git init --separate-git-dir /path/to/existing-bare-repository /path/to/workdir
    $ cd /path/to/workdir
    $ git checkout .
    

    Voilà!

    For info: git init will report: Reinitialized existing Git repository in /path/to/existing-bare-repository. But be confident. man git-init says: Running git init in an existing repository is safe. It will not overwrite things that are already there.

    The magic is that git init alone does not make your files appear in the working directory. You have to checkout the root directory.

    0 讨论(0)
提交回复
热议问题