Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cloning a Git repo into a new repo - without commit history

So I'm trying to get my head around Git, and have the need (why I have this need I won't go into) to be able to take the files from one repo, via command line, and put them into a brand new repository WITHOUT taking all of the previous commit history with it.

What I'm trying to do at the moment is git init to create a new repository, and then grab the files from my existing repo, either using clone or subtree (I've not got my head fully around this yet so may be barking up the wrong tree), and then add, commit, and then push these to my new repository.

git init
--- get the files from stock repo ---
git add .
git commit -m 'Initial commit'
git remote add origin <url of my new repo>
git push -u origin master

My repositories are all on Bitbucket, if that makes a difference,

like image 481
Tom Avatar asked Nov 14 '14 18:11

Tom


People also ask

Can you clone a Git repo into another repo?

Just for the record, you can clone a git repo within another one: Everything under your lib directory will be ignored by the enclosing Git repo, because said lib directory contains a . git . That means cloning the enclosing repo, and you will get an empty " lib/ " folder.

Does Git clone copy commit history?

Each clone usually includes everything in a repository. That means when you clone, you get not only the files, but every revision of every file ever committed, plus the history of each commit.


1 Answers

You can clone the old repository like:

git clone [email protected]:username/repository.git

and then you delete the git directory:

rm -rf .git/

Now you create the new repository:

git init
like image 112
Florian Rusch Avatar answered Dec 05 '22 05:12

Florian Rusch