0

I had an old project, which I committed to GitHub. Then I had a new project and on this one I could reuse some of the old code from the old project. So I duplicated the folder and opened it on vscode to rewrite my code.

The thing is, the terminal on vscode is still connected to the GitHub remote server from the old project and I need to disconnect it and commit it as a new repository on GitHub.

I researched about it but couldn't really find any case similar to this.

I'm new to this. I know it's probably really basic stuff, but it would be awesome if someone could help me with this.

Thanks in advance! :)

anahperes
  • 1
  • 1
  • Terminals don't actually "connect" in the way you're describing. Probably all you need to do is change or remove the `remote` for your Git repo. Type `git remote -vv` from the command line to see your current remotes. Note you commit locally, and then push commits to a remote. If all you need is to change your remote for the copy of the repo, see [this question](https://stackoverflow.com/q/2432764/184546). You may be interested in using a fork too (or instead of a new repo). – TTT Jun 07 '23 at 19:10
  • Did you copy the `.git` folder with that old project? If you're creating a new repo unrelated to the old one, delete that folder from the copy and start fresh. – joanis Jun 08 '23 at 01:42
  • @joanis is right **if you're creating a new repo**. But if you have new work in that repo already, you don't want to delete the `.git` folder. – TTT Jun 09 '23 at 15:56
  • @TTT Reading the question, it was my impression that OP is creating a new project in which they want to include a copy of old code but disconnected from their old project. – joanis Jun 10 '23 at 00:24
  • @joanis I agree that's the most likely interpretation. I mentioned it just in case they have new commits or other things in the repo they wish to keep. – TTT Jun 10 '23 at 02:28
  • First of all, thank you @TTT and @joanis. When I finally tried to push my commits to the remote repository I got the following message "error: remote origin already exists.". Here is what I did to fix the problem: 1. I used `git remote -v` to check out to which remote I was "connected" to and noticed it was, indeed, the one from the old project. 2. So, I used `git remote set-url origin https://newurlhere.com` to specify the new repository address. 3. It was only then that I could, once again, use my origin repository to commit my files to the correct place. – anahperes Jun 20 '23 at 17:54

1 Answers1

0

When I finally tried to push my commits to the remote repository I got the following message "error: remote origin already exists.".

Here is what I did to fix the problem:

  1. I used git remote -v to check out to which remote I was "connected" to and noticed it was, indeed, the one from the old project.
  2. So, I used git remote set-url origin https://newurlhere.com to specify the new repository address.
  3. It was only then that I could, once again, use my origin repository to commit my files to the correct place.

Here is where I found more information about the error: https://www.cloudbees.com/blog/remote-origin-already-exists-error

anahperes
  • 1
  • 1