how to restart a git repository
Asked Answered
G

3

13

I just realized that changes to the .gitignore do not process against the repo “retroactively” – rather affect future ‘git add *’ commands and the like. Once the files are in the repo – they must be manually removed.

At this point – I would like just kill this repo entirely – and start over (saving my config, etc.).

Is this easily possible or would it cause major problems? Can I backup – then delete the .git folder – and start fresh?

Goldfilled answered 6/3, 2013 at 10:21 Comment(3)
why don't you like the idea of just removing the files from source control?Ummersen
There are many files nested in deep folders.Goldfilled
Does this answer your question? How to restart git repo?Fourway
F
16

Can backup – then delete the .git folder – and start fresh?

Yes. This is all there is to it.

Some really exotic set-ups might have the .git folder outside of the working directory; but otherwise the .git folder contains all the information there is wrt git. If you remove that, you remove all history, git-metadata and such.

If you had remotes, the link to them is lost, as that is stored in the same .git folder. The remote itself, on say your Gitlab server, is obviously not gone. So if you re-add that same remote on your clean environment it will cause history to re-appear, which might cause merge conflicts.

Edit: for those who might not have read the entire question: warning: this will remove all your git history.

Flasket answered 6/3, 2013 at 10:43 Comment(1)
Thank you for your help. I thought you could simply delete this folder - but then I saw another post which indicated it would be a big problem.Goldfilled
U
19

I do this all the time. got into the working directory and if your on linux or mac do a

rm -rf .git

then I do a

git init
git add .
git commit -m "first time load"

that's all you need

Unmanly answered 6/3, 2013 at 12:57 Comment(0)
F
16

Can backup – then delete the .git folder – and start fresh?

Yes. This is all there is to it.

Some really exotic set-ups might have the .git folder outside of the working directory; but otherwise the .git folder contains all the information there is wrt git. If you remove that, you remove all history, git-metadata and such.

If you had remotes, the link to them is lost, as that is stored in the same .git folder. The remote itself, on say your Gitlab server, is obviously not gone. So if you re-add that same remote on your clean environment it will cause history to re-appear, which might cause merge conflicts.

Edit: for those who might not have read the entire question: warning: this will remove all your git history.

Flasket answered 6/3, 2013 at 10:43 Comment(1)
Thank you for your help. I thought you could simply delete this folder - but then I saw another post which indicated it would be a big problem.Goldfilled
S
4

The best strategy for handling this would be to use the git archive command. This will export an unversioned version of your tree in a tar archive. Select your branch that you'd like to export and run the following inside your repository:

git archive master | tar -x -C ~/target/directory

You can then cleanly delete your repository folder and then extract your archive to start anew. Finally, you can create a new repository in your extracted folder as follows:

git init
Stevestevedore answered 6/3, 2013 at 10:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.