3

I want to create a master repository on our server, from which I can clone a local version onto my computer.

I am using R Studio v0.98.994.

So far, this is what I have tried doing:

Create a folder for the master repository to live in. I do this using 'new project' in R studio, and tell it to make a git repository.

I can then open up another new project, located on my C drive, and use R studio to clone, by telling it to open an existing project and setting the URL as the location of the master project.

However, then when I make changes and commit to my local repository (which works fine) I cannot push to the master repository, I get an error exactly as described in this question: git push fails: `refusing to update checked out branch: refs/heads/master`

So it appears that R Studio creates non-bare repositories?

Now I thought, well okay, I will use git bash to initialise the repository and then connect to that within R studio.

I do so, but cannot then find a way to use that repository in R Studio.

I am very new to Git, so it is entirely probable that this is one of those 'read the instructions' questions, in which case I am very sorry - and could someone possibly point me towards some guidance for this situation? I have spent the better half of a day googling around this error and haven't yet managed to pull together the pieces :( I also apologise; this doesn't feel like a very reproducible question.

Community
  • 1
  • 1
Froom2
  • 1,269
  • 2
  • 13
  • 26
  • 1
    RStudio's implementation of `git` is just a wrapper for the core `git` functionality, really. What is the OS of your server and your client? – TARehman Mar 17 '15 at 19:13
  • By server, I really just meant like, as opposed to C: drive, it's a server and we call it the S: drive :( So It could equally be that I want a 'remote', safely untouched repository on the C drive, and then a working 'local' repository... if that makes sense? :S our computers are using Windows 7. – Froom2 Mar 18 '15 at 09:21
  • 1
    I think your question is more a Git question than an R question. While you're right that this isn't a very reproducible question, I'm going to try and assist since you've clearly put in some effort to solve it. – TARehman Mar 18 '15 at 16:40

1 Answers1

5

It sounds like you are using Windows Git, with a setup on a local Windows machine (C: drive) and a server of some kind, mounted as the S: drive. There's a few things you should be aware of when doing this.

Shared Repositories

If you are intending for multiple people to share the same repository, you want to initiate a shared repository. See the --shared option in git-init for more details. Note that I'm not sure how having your repository on a Windows machine affects the sharing options. If you are just trying to keep your repository in two places, that makes things a lot easier.

Bare Repositories

Separate from the discussion of sharing is the discussion of bare repositories. If you don't intend to ever work with files in the server (i.e. it's just going to be a place to push changes so they are safely stored), you could initialize a bare repository. A bare repository contains the database structure of Git, but does not have the actual files in the directory.

A standard Git repository is a directory with a hidden folder in it named .git. This .git folder contains all the various data structures that Git uses to track changes. A bare repository is essentially a folder containing only the contents of .git.

The good thing about a bare repository is that no one can work in the repository itself (since there is no working directory, just the database). This means that no one could log into S: and edit the repository themselves. Instead, they would have to clone the repository, then push their changes back to the origin. The GitGuys have a good article about why this is ideal.

Note that shared repos and bare repos are not dependent or mutually exclusive. As a general practice, if you are having a "server repo" from which you pull and to which you push, you should have it be bare, regardless of whether the project is shared.

A Non-Shared Workflow

Since it's not clear if you are sharing or not sharing and you're on a Windows environment, which I don't know about from a sharing standpoint, I'm going to give you a simple example. Using git-bash, you should be able to change directories to wherever on S: you have your repositories. Then, use git init with the bare options as described by the link above to initialize a bare repository. Navigate to where you want your repository to live on C:, and then do git clone to get a working copy.

Add a README file or something else so you can do your initial commit, and then commit and do git push origin master to push your changes to the S: repository. Once all that is done, THEN initialize the RStudio Git project. RStudio should defer to your existing configuration, and things should hopefully work.

TARehman
  • 6,659
  • 3
  • 33
  • 60
  • If I could upvote and accept your answer another ten times, I would. Thank you for such a beautifully laid-out and thorough reply! I am going to go and see if I can get this working now. – Froom2 Mar 19 '15 at 12:48