14

I am currently struggling with getting Rstudio to work with my git repositories. When I set up a new project and assign the git repository, the branch is set on Master and the commit, pull, and push buttons are all active. Everything works just fine. Then, at some point the branch is switched to (No Branch) and the commit, pull, and push buttons are greyed out (shown below). This happens to every single git project I make. Works at first then is greyed out.

enter image description here

I am still able to use git commands from Shell, but the GUI interface is not working.

I have spent some time looking through customer support forums and Googling the problem. One site that I found (https://www.r-bloggers.com/things-i-forget-pushpull-greyed-out-in-rstudio/) indicated that there is an issue with the configuration list. However, when I do git config --list, I find that I do have branch.master.remote=origin and branch.master.merge=refs/heads/master at the bottom of the configuration.

I also attempted a git push -u origin master, but that did not work either.

I use RStudio and github daily, and I would be so pleased if the GUI interface was working properly again.

I would be very grateful if someone could help me problem solve this issue.

EDIT: I am using OSX 10.9 Mavericks and Rstudio Version 0.99.903.

Xander
  • 543
  • 1
  • 5
  • 18
  • 1
    What OS are you using? – sebastian-c Oct 11 '16 at 12:13
  • I am using OSX 10.9 Mavericks. I edited the original post to include this information. – Xander Oct 11 '16 at 12:28
  • 1
    Try looking at the remotes for a particular project. In the shell: `git remote -v`. There should be 2 lines there starting with "origin" and followed by the remote address. Is that what you see? Are there any remotes listed there at all? Also, is your remote repository "available" to you (if it's on a local network, are you connected to that network, and is the server active)? – rosscova Oct 11 '16 at 12:55
  • @rosscova Thank you for your inquiry. Yes, when I use `git remote -v` is see two 'origin' lines with the url that goes to my git project: `origin https://github.com/username/rep.git (fetch)` The remote repository is available given that it is hosted on github and I have internet connectivity. – Xander Oct 11 '16 at 14:42
  • 1
    There should a be a log file at `~/.rstudio-desktop/log/rsession-.log` (replacing your own username for ``); do you see any exceptions within there that seem related to git? – Kevin Ushey Oct 11 '16 at 22:55
  • @KevinUshey This was another good idea. I checked both that log file as well as the `rdesktop.log` file and searched both for 'git'. Both did not contain any information related to it. – Xander Oct 12 '16 at 00:03

4 Answers4

16

I had a similar problem with a repo I had already configured locally and pushed and pulled from/to it using CLI (although I didn't have the problem of being detached from a branch) and I solved it by doing the following:

  1. Open your console and navigate to your repo
  2. Make some commit
  3. Make a push using -u (i.e. --set-upstream) flag, eg: git push origin master -u
  4. Open Rstudio (or restart it if it was open while performing the previous step) and you'll see the push and pull icons are no longer greyed out.
andschar
  • 2,731
  • 1
  • 23
  • 32
ccamara
  • 854
  • 1
  • 10
  • 26
  • Thank you for your reply and suggestion. I followed all of the steps that you recommended on two different git repos. Unfortunately, when I started up RStudio again, it is still on (No branch) and the buttons are greyed out. – Xander Oct 20 '16 at 00:16
  • If you access to the CLI are you working on a branch or on the contrary you're detached from one? If so, please refer to the previous answer and then execute this command. – ccamara Oct 20 '16 at 04:03
  • 1
    If git is working fine on the CLI I'm afraid the problem is either in your project configuration or r studio's configuration. Just to make sure: are you using the right git path in R Studio s configuration? – ccamara Oct 20 '16 at 04:08
  • This latter problem could be checked by creating a new project with a new repository from scratch and see if that's working. (sorry for so many comments, but I can't edit mine on the smartphone) – ccamara Oct 20 '16 at 04:16
  • it turns out to be an RSA key issue. The wrong key was in the Rstudio Config, which explains how Shell would work but not the Rstudio interface. Thank you for your help. – Xander Oct 20 '16 at 08:26
  • This also helped me fix an issue where the git repo url changed and I had changed the remote in the git command line but R studio was no longer giving status updates like x commits ahead or origin and I got warnings that the repo moved when I pushed. – see24 Mar 16 '22 at 20:08
4

Then, at some point the branch is switched to (No Branch) and the commit, pull, and push buttons are greyed out (shown below).

That is typical of a detached HEAD branch: see "Why did my Git repo enter a detached HEAD state?".

Revert to the command-line and check your git status.

You can easily recover from this by a checkout of a branch.
Or by forcing a branch to your current detached commit

git branch -f branch-name HEAD
git checkout branch-name

Then switch back to RStudio: all options should be available again.


As commented:

Tt turns out to be an RSA key issue.
The wrong key was in the Rstudio Config, which explains how Shell would work but not the Rstudio interface.

Community
  • 1
  • 1
VonC
  • 1,129,465
  • 480
  • 4,036
  • 4,755
  • 1
    Thank you for your reply. When I run `git status` on command-line (OSX Terminal) executed from Tools -> Shell... within RStudio, the response reads: `On branch master Your branch is up-to-date with 'origin/master'.` Likewise, when I attempt the `git branch -f master HEAD` the return is `fatal: Cannot force update the current branch.` The return for `git checkout master` is `Already on 'master' Your branch is up-to-date with 'origin/master'.` All options on Rstudio remain unavailable even after restarting. It seems that the head is not actually detached... – Xander Oct 14 '16 at 01:23
  • @Xander True, HEAD is not detached. What version of Git are you using? – VonC Oct 14 '16 at 07:19
  • Thank you for the reply. I am running `git version 2.8.1` – Xander Oct 16 '16 at 10:10
  • @Xander Is there any permission issue (as in the repo would not be owned by the same user than the one executing RStudio) – VonC Oct 16 '16 at 18:16
  • I only have one github account, only ever made one RSA key, and that key is correctly listed in Rstudio's preferences. Besides, if there was a permission issue, I do not think git commands would work in command line either. – Xander Oct 17 '16 at 03:10
2

I just wanted to provide an update in case anyone in the future had a similar problem. While the answer provided earlier resulted in another temporary fix, I ultimately had to wipe my hard drive; reinstall the operating system; reinstall git, R, RStudio, and reconnect to my Github account before it would consistently work.

My solution may have been a bit overkill, but I have not had an issue with it since.

Xander
  • 543
  • 1
  • 5
  • 18
-1

I had the same issue today and found this post. I am going to share how I solve it:

on terminal (Git) type the following: $ git config --global user.name (it should return your Github username)

if username isn't correct just type $ git config --global user.name "correct_username"

then type $ git config --global user.email (it should return an email associated to your GitHub account)

I found a typo in my email and fixed it by typing $ git config --global user.email "correct_email"

Then I added the origin (this you get it from GitHub) $ git remote add origin https://github.com/my_username/my_repository.git

Then I setup the branch, most used ones are main and master, in my case it is main $ git branch -M main

then I pushed from the terminal $ git push -u origin main

after that my pull and push buttons are active.

I hope this can save some time for others.

lhs
  • 913
  • 10
Ernesto F
  • 1
  • 1