3

When a repository is cloned by using simple git clone repo, the master branch is automatically checked out. If after this automatic checkout, I want to delete all files checked out and turn the clone in to a bare clone, how can I achieve this? Are there configurations within the .git folder that I can modify to accomplish this?

Side note: I know that specifying the --no-checkout or -n flag during clone prevents checkout of HEAD and keeps the repository bare. If I delete the files that are checked out, those files will be shown as deleted when running git status.

LightBender
  • 4,046
  • 1
  • 15
  • 31
Ali
  • 1,442
  • 1
  • 15
  • 29
  • Possible duplicate of [How to convert a normal Git repository to a bare one?](https://stackoverflow.com/questions/2199897/how-to-convert-a-normal-git-repository-to-a-bare-one) – phd Sep 11 '17 at 19:10

2 Answers2

3

git clone --no-checkout doesn't give a bare repository, it just leaves the work tree and index empty. git status after such a clone will say that all files have been staged for deletion.

A bare repository is one with core.bare = true (and a bare repository made with git clone --bare will also not have any remote refs). You can do git config core.bare true to flip this bit. Then remove the work tree and index, and possibly rename the directory from repo/.git to repo.git.

Josh Lee
  • 171,072
  • 38
  • 269
  • 275
0

I don't get your question.

In my understanding, if you want to clear a repository then after cloning delete the files you don't want and push.

If you want to checkout into a new branch then use this command:

git checkout -b your-new-branch-name
Andrew Myers
  • 2,754
  • 5
  • 32
  • 40
codelover
  • 131
  • 1
  • 10
  • That is not what I am trying to accomplish. My intension was to clone a bare repository. But I did not specify the -n or --no-checkout flags. I do not want to delete files from remote repository. I just want to turn my local repository into a bare repository by 'somehow' getting rid of local master branch. – Ali Sep 11 '17 at 15:35