What is the best way to move the content of my current main branch to a sub-branch?
-
Depends on what is wrong with the repository you have. But if you want to discard anything it contained either way, deleting it is easiest. – Jan Hudec Oct 02 '14 at 13:58
-
In what way is it messed up? – Holloway Oct 02 '14 at 14:04
-
It seems a duplicated one: http://stackoverflow.com/questions/2006172/how-to-reset-a-remote-git-repository-to-remove-all-commits – dfranca Oct 02 '14 at 14:05
-
I want to keep my history "clean". I made commits that had errors in the code etc.. I would like to clean out the repository and make a fresh new initial commit and start from there. – jpd Oct 02 '14 at 14:55
3 Answers
Try create a new repository, then change the url-origin in your .git/config with this command
git remote set-url origin git://new.url.here

- 442
- 1
- 6
- 21
You cannot create another git repository into existing git repository.
I am explaining the way I am understanding your problem. I am assuming the folder structure is, like :-
= Parent Directory
== Old Directory (git already initialized)
== New Directory (use git init to initialize git repository)
There one 'parent' directory which contains sub-directories and git is initialized under those directories. If you use in this way then it will work.
If you are thinking to use following directory structure
= Parent Directory == Old Directory (git already initialized) === New Directory (to initialize git repository with-in git repository, then it will not work)

- 440
- 3
- 8
In git if you want to throw out your local changes you don't need to delete and recreate the repository.
Just do something like
git checkout BRANCH_WITH_COMMITS_I_DONT_WANT
git reset --hard origin/BRANCH_WISH_COMMITS_I_DONT_WANT
Note this is not working directory safe Note that you will eventually lose all your local commits and the work contained in them, but this sounds like what you are after.
Resetting your branch is significantly faster than deleting and recloning in most cases.

- 13,845
- 6
- 50
- 57