How to convert a normal Git repository to a bare one?

后端 未结 17 985
礼貌的吻别
礼貌的吻别 2020-11-22 08:05

How can I convert a \'normal\' Git repository to a bare one?

The main difference seems to be:

  • in the normal Git repository, you have a .git

17条回答
  •  情歌与酒
    2020-11-22 08:12

    The methods that say to remove files and muck about with moving the .git directory are not clean and not using the "git" method of doing something that's should be simple. This is the cleanest method I have found to convert a normal repo into a bare repo.

    First clone /path/to/normal/repo into a bare repo called repo.git

    git clone --bare /path/to/normal/repo
    

    Next remove the origin that points to /path/to/normal/repo

    cd repo.git
    git remote rm origin
    

    Finally you can remove your original repo. You could rename repo.git to repo at that point, but the standard convention to signify a git repository is something.git, so I'd personally leave it that way.

    Once you've done all that, you can clone your new bare repo (which in effect creates a normal repo, and is also how you would convert it from bare to normal)

    Of course if you have other upstreams, you'll want to make a note of them, and update your bare repo to include it. But again, it can all be done with the git command. Remember the man pages are your friend.

提交回复
热议问题