How to create a separate Intellij project from a GitHub repo for another project?

I have an old Intellij project, which I continue to develop. From it, I'd like to create a new, independent project, with its own GitHub repo. I'd also like to remove all the previous commits, except for the last one.

Question: What's a clean way to do this?

Tried: I've created a "New" project by cloning the "old" repo. Trying to share the "new" project on the GitHub via Intellij gave me the "old" repo url and a warning that the "Remote is already on GitHub". But I'd like to share the project to a new repo.

Upvotes: 0

Views: 396

Answers (1)

Brian
Brian

Reputation: 96

try these steps:

1) clone the repo again

git clone git://server.com/my-repo1.git

Do this in a new location

cd /parent_folder

then

cd /new folder 

2) Remove all entries and their history, creating a clean git repository that contains only data and history

git filter-branch --subdirectory-filter your_dir -- -- all

3) Move all your content so it will not conflict with the new repo merge

mkdir new_directory/
git mv my_stuff new_directory/

4) Commit your changes

git commit -m

5) go to your repo

cd ../my-repo2/

6) connect your source repo as a remote using a local reference

git remote add repo1 ../my-repo1/

7) now fetch that source, create a branch and merge with the destination repo

git fetch repo1
git branch repo1 remotes/repo1/master
git merge repo1 --allow-unrelated-histories

8) push your changes

git remote rm repo1
git branch -d repo1
git push origin master

Upvotes: 1

Related Questions