Let’s say the repository you want to clone is https://github.com/example/public_example.git
You want to clone this repository to your local computer and then push it to your private Github repository.
git clone https://github.com/example/public_example.git
Now the public repository is cloned to your local computer.
This step is important: You need to clean the
rm -rf .git #this will clean all git directories and its contents
At this stage, you should have your private repository created on the Github site. You can create it from here. Don’t forget to choose the Private Repository option.
Now, it’s time to push your directory to your newly created private Github repository:
git init git add README.md git commit -m "first commit" git branch -M main git remote add origin https://github.com/youruser/private_example.git git push -u origin main
If you encounter the following error:
error: failed to push some refs to …
This is how I solved this error:
git commit -m "ne2" git status -u
git reset --hard HEAD
now, remove existing local git:
rm -rf .git
Create a new one:
git init git add README.md git commit -m "first commit" git branch -M main git remote add origin https://github.com/XXXXX.git git push -u origin main
This solves the problem.