Rstudio: Changing origin for git version control of project
Asked Answered
G

4

15

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?

Gonzalogoo answered 11/9, 2016 at 10:46 Comment(2)
I would suggest just doing this from the command line / shell; I don't think anything is exposed within RStudio's git integration for handling this. Odds are you just need something like git remote set-url origin <origin-url>. After that, RStudio should detect the updated remote location.Unquote
Did you know the rules how Rstudio detect the remote location?Quahog
O
24

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.

Oasis answered 24/9, 2016 at 17:43 Comment(0)
I
3

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.

Illgotten answered 24/4, 2018 at 12:6 Comment(0)
D
3

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.

Desmoid answered 2/5, 2022 at 19:2 Comment(0)
Q
0

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.

Quahog answered 21/1, 2019 at 3:4 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.