Thursday, July 16, 2020

Changing Git Remotes

I had a recent problem with Git that was a real pickle to figure out how to solve, but the solution was remarkably simple.

I have an old project we'll call Legacy. I wanted to rework it, but in a new repository, since my client didn't want Legacy itself altered. I needed to clone it, but then push it to a new Git repo. Here's how it goes.

Clone Legacy
git clone https://github.com/legacy

Remove all git references by deleting the .git folder at the root of the project. At this point we have a project directory full of code and resources, but not connected to a repository.

Initialize git and add our files
git init
git add [files to add]
git commit

Now we hook it up to our new repository. For my case I had already created the repository on GitHub prior to doing the following steps.
git remote add origin my_new_repository_url
git push -u origin master

Now you should be good to go. 

No comments:

Post a Comment