3

I'm a little lost. I worked on a project, which is coupled with github. But I made the project evolve and therefore I created on github a new repository with which I wish to work (while keeping aside the old one with the old files).

So in my project I want to make sure that it is no longer coupled to the old repository and that I can work normally from the new one.

I followed some links and so I did:

  • Creation of my new repository on Github
  • In my project : git remote rm origin
  • git remote add origin [newGithubURL]
  • git init , git add . , git commit -m "first commit"
  • git push origin master

But I've this error :

enter image description here

phd
  • 82,685
  • 13
  • 120
  • 165
eronn
  • 1,690
  • 3
  • 21
  • 53
  • Do you want it to truly be a new repository as if it started from scratch, or do you want to retain your old commits for reference? – chrisbyte Dec 13 '19 at 15:03
  • 1
    If you're not concerned about what's currently in the new repository, you could try `git push --force origin master` – Mike Faber Dec 13 '19 at 15:03
  • I want it to be a new repository so that I balance all of my files in it. And concerning the previous deposit, I leave it aside with the old commits – eronn Dec 13 '19 at 15:05
  • @eronn if the solution @Mike Faber provided does not work, I have had success by copying the entire local folder to a new folder, deleting the `.git` folder in the new one, then doing `git init` etc. as you have described. That way it is treated as a new repository with no history. – chrisbyte Dec 13 '19 at 15:08
  • Okay it works thank you very much! The problem was the readme! So I was able to put everything in the new repo. Good by cons he put me all my previous commit and I would have preferred to act as if I started from scratch but good – eronn Dec 13 '19 at 15:08
  • Does this answer your question? [Issue pushing new code in Github](https://stackoverflow.com/questions/20939648/issue-pushing-new-code-in-github) – phd Dec 13 '19 at 15:19
  • https://stackoverflow.com/search?q=%5Bgit-push%5D+updates+were+rejected – phd Dec 13 '19 at 15:20
  • This might be similar issue and it shows a different approach. https://stackoverflow.com/questions/5181845/git-push-existing-repo-to-a-new-and-different-remote-repo-server – user0904 Jan 18 '21 at 20:38

1 Answers1

6

@Mike Faber provided a great solution that would retain the history of the old repository within the new one.

If you want to start over from scratch as if it were a brand new repository, what I have done is:

  1. Copy the local working folder for the old repository to a new folder
  2. Rename the new folder to what you want it to be, or, archive or rename the old folder as a backup
  3. Delete the .git folder in the new working folder
  4. In the new folder, do git init, git add . , git commit -m "first commit" as you normally would to push to GitHub

Now you have a copy of the old repository, as a new repository, starting with only one commit.

chrisbyte
  • 1,408
  • 3
  • 11
  • 18