'Rstudio: Changing origin for git version control of project

I originally set up git in Rstudio while enrolled in the Data Scientist's Toolbox course at Coursera. Unfortunately, I did this in my phd project. The repository no longer exists on github. I am now attempting to write my thesis in rmarkdown using knitr and bookdown. I would like to use version control, both to learn proper git workflow and to have a structured back up of everything I have done in my thesis. However, I have been unable to change the version control repository in Rstudio.

  • I am unable to change this in the Tools > Version control > Project setup > Git/SVN menu. The Origin: textbox is unchangable.
  • I tried creating a new project using the old phd project's working directory. This also cloned the version control settings.

How do I change the origin to accomplish what is described above?



Solution 1:[1]

Git, Github and Rstudio are different things. You could use git as local version control tools. You might connect your local repo to Github account which is based on git by push/pull. Rstudio just makes a user interface for git and supplies the function to push the repo into remote server based on git to make version control(not only Github, but also Gitlab).

So for your issue, if you do not want to pay for github for a private repo, all of your code would be public and I don't think it is good before your finally finished your thesis. But version control could be made locally with git only. Just use git shell to control the version.

However, as a student, github could support private repo here for you. Just register and find your student package. Then just remove the url for remote repo after you cd to your workdir in command line, use the following code to find your remote url(mostly you might fing origin):

git remote -v

Then use this to remove them:

git remote rm origin

Now you could use version control locally. If you want to connect this repo to your remote github private repo, use this:

git remote add origin https://github.com/[YourUsername]/[YourRepoName].git

RStudio would find this information about git and support your following operation. Project in RStudio is different with git, although project support git as version control tool. So you need git in command line or shell to solve your problem.

Solution 2:[2]

This can be done by opening /your.project/.git/config and editing the remote origin line(s), e.g. changing from git to https. Restart Rstudio & you'll be prompted for your github username & password.

Solution 3:[3]

After testing, I found some clue
Actually Rstudio is not really smart about this setting

It will first search for the git file in the Rproject folder where your Rporject file is located if it could not, then it goes up to the folder contains your Rproject folder However, for version control you only need coding files while RProject may contains some big files like .RData some pictures etc.

I don't find a way to manually disrupt this logic flow, the only thing you can do is to delete the current git repository setting files(which is .git folder and 2 other git setting files), then Rstudio may ask you if you want to init a new one.

Solution 4:[4]

This is what worked for me for migrating from github to Azure

Go to the top right Git window in RStudio and click on the gear. Now click Shell (to open the terminal there).

#remove origin

git remote rm origin

#add new origin like Azure for me via HTTPS

git remote add origin https://[email protected]/USER/PROJECT/_git/REPONAME

#push your local repro

git push -u origin --all

#in my case put in the PAT password if you needed to generate one.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 yufree
Solution 2 dez93_2000
Solution 3 cloudscomputes
Solution 4 Brandon Rose