What is a bare repository and why would I need one?

前端 未结 2 662
失恋的感觉
失恋的感觉 2020-11-27 06:09

This maybe has been answered, but I didn\'t find a good answer.
I come from centralized repositories, such as SVN, where usually you only perform checkouts, updates, c

2条回答
  •  心在旅途
    2020-11-27 06:46

    Why would I need one ?

    The link "but why do I need a bare repo?" from the VonC answer could be completed with two use cases I have found recently.

    The first is essential to know imho, while the second could be criticized.

    A - To sync you home dot files

    No more symlinks which point to you git repo. Just use:

    git init --bare $HOME/.myconf
    alias config='/usr/bin/git --git-dir=$HOME/.myconf/ --work-tree=$HOME'
    config config status.showUntrackedFiles no
    

    where my ~/.myconf directory is a git bare repository. Then any file within the home folder can be versioned with normal commands like:

        config status
        config add .vimrc
        config commit -m "Add vimrc"
        config add .config/redshift.conf
        config commit -m "Add redshift config"
        config push
    

    One of the major benefits is that it prevents nested git repos. More details on the source

    B - To host a Git project inside a cloud-synced folder

    It is not a good idea to create a .git/ dir inside a cloud-synced folder because the synchronization could mess everything up. But using the same technique as above you can use a bare repository outside the synced dir to use versioning and still have the comfort of a synced dir.

提交回复
热议问题