Move an existing GitHub repo to a new one
In the event of having to move one github repository a different repository, due to needing to separate professional and personal accounts, the following commands should complete the task.
1 Disconnect the local repository from GitHub
The first step is disconnect the local repository from GitHub. In an RStudio session, click on the “Terminal” tab in the Console pane. Navigate to the root directory of the git repository using the command line. It may be the case that navigating to the directory is unnecessary if it’s the same as the RStudio project directory. Finally, type the following bash command to disconnect the local git repo from the GitHub one.
git remote remove origin
2 Create a new GitHub repository
The next step is to create a new GitHub repository.
3 Connect the local git repository to the new GitHub repository
When the new GitHub repository is created a set of commands are provided on the git hub web site. Those commands can be copied and pasted into the terminal, executed in the terminal, and should complete the setup. Notice that when copy-pasting the first two lines may execute themselves but the third one will need to be executed manually.
git remote add origin https://github.com/{USER}/{REPO}.git
git branch -M main
git push -u origin main