How To Set Your Local Repository To New GitHub Repository?

Remove your existing remote URL in your current project and set it to a new remote URL in Github's repository.

How To Set Your Local Repository To New GitHub Repository?

For some reasons, you don't want to use your existing remote repository (repo).

You create a new GitHub's repo. How to push your current code to the new repo?

Check your remote repo URL

git remote -v

origin  https://github.com/ansonlowzf/your-repository.git (fetch)
origin  https://github.com/ansonlowzf/your-repository.git (push)

It returns the remote URL set to your project.

Remove the URL from your project

$ git remote rm origin

Afterwards, run

git remote -v

If the terminal returns nothing, it means you successfully remove the remote URL.

Create a new repository in GitHub

Then, run

git remote add origin https://github.com/ansonlowzf/your-NEW-repository.git

Check the remote URL again with:-

git remote -v

origin  https://github.com/ansonlowzf/your-NEW-repository (fetch)
origin  https://github.com/ansonlowzf/your-NEW-repository (push)

If the terminal returns your new remote URL.

Congratulation, you can start push your code to the new remote URL.

Set upstream

git push -u origin main

­čôŁGitHub encourages us to use origin "main" instead of origin "master". If you are so used to use the origin master. You can still set the upstream to master as you like.