Rstudio greyed out Git commands and (No branch) - r

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.
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.

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:
Open your console and navigate to your repo
Make some commit
Make a push using -u (i.e. --set-upstream) flag, eg: git push origin master -u
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.

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.

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.

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.

Related

Receiving the following error when pushing commitments to Github in R: error: cannot run rpostback-askpass: No such file or directory fatal:

I want to push some changes to my GitHub repository and I receive the following error, which I have been trying to solve for the last couple of hours.
error: cannot run rpostback-askpass: No such file or directory
fatal: could not read Username for 'https://github.com': Device not configured
What I have just done is
Open a new repository on Github
Go to code and copy the https link
Go to R Studio > New Project > Version Control > Git
Paste the https link to repository URL
Write some code and save it to an R file
Select the file > Commit > and Push
and I receive this error, which I was not getting previously. (Note that I took a long break and during this time I have not committed anything to Github but previously, I have not face any error like that.)
I have searched some solution on the internet, while some suggested to use SSH key instead of https, I could not find a neat solution (that might be because I am not familiar with the Github workflow)
Therefore, I would appreciate if you can just provide me a clean solution on how to solve this problem. Thank you for your attention beforehand.
PS: I am using a Mac if that would matter.
This should be linked to the lack of credential helper which means Git is trying to read credentials from your terminal, since it exhausted other options.
Check your git config --global credential.helper first.
Try and install GCM, the Git Credential Manager (which is no longer GCM-core).
And reference it in your config:
git config credential.helper manager

cannot set up PAT authentication for git on linux server via rstudio

I have access to a Linux server at work where I code in RStudio. Recently, the pull/push buttons have been greyed out in the git pane, and I also haven't updated from basic password authentication which I know GitHub is deprecating soon. However, I can't get it to accept a PAT, and clearly this repository has gotten unlinked from GitHub somehow.
When I run git remote -v from the terminal, I see the correct repository and branches.
When I run gitcreds::gitcreds_set() from R, it shows my correct GH username, and that it has saved a password. It then gives me an option to replace the credentials, but when I put in a new PAT (shown below as XXXXXX), I get an error:
-> What would you like to do?
1: Keep these credentials
2: Replace these credentials
3: See the password / token
Selection: 2
-> Removing current credentials...
? Enter new password or token: XXXXXXXX
Error in new_git_error("git_error", args = args, stdout = out, status = attr(out, :
System git failed: error: unknown option `get-urlmatch'
usage: git config [options]
I tried googling this error but haven't come across anything useful. Thanks in advance for any ideas. I imagine that fixing the git connection will also fix the greyed-out push/pull buttons in RStudio.
The --get-urlmatch option to git config first appeared in Git version 1.8.5. While any modern Linux system will ship with a Git version of at least 2.0, there are a bunch of rather old systems that still come with Git 1.8 or even 1.7 variants.
There might be a way to work around this in RStudio, but your best bet is probably to get a newer Git version installed on the system. Git is generally pretty backwards-compatible although there were a few user-interface-default changes between 1.x and 2.0 (and there's another one coming up, though I doubt anyone will call this 3.0).

After updating R and RStudio, push to GitHub fails stating remote is ahead even though it's not

I am having some sort of communication issue with my RStudio project and GitHub, potentially related to updating R and RStudio.
I recently updated my R to version 4.0.3 on my windows machine:
R version 4.0.3 (2020-10-10); Platform: x86_64-w64-mingw32/x64 (64-bit)
I also updated my RStudio to Version 1.3.1093, and finally, as a result of the issues below, I updated my git version to 2.30.0.windows.1
I have two existing R Packages hosted on GitHub, and recently created a third. To create my new Repo and link it to my local project I followed the instructions on:
https://aberdeenstudygroup.github.io/studyGroup/lessons/SG-T1-GitHubVersionControl/VersionControl/
I have interacted with GitHub to update my current packages, but it's been years since I created a new repository. It wasn't easy but eventually everything seemed to be working properly. I made some edits, performed a commit, went to push (using the shell or RStudio's GUI) and got this error:
To github.com:user/repo.git
! [rejected] HEAD -> main (non-fast-forward)
error: failed to push some refs to 'github.com:user/repo.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
I am the only person using this repo, and when I perform a pull, I'm told everything is up to date. I also found a post suggesting I first fetch, then rebase (Git push rejected "non-fast-forward"). When I tried these steps I got an error:
$ git rebase tmp
error: could not apply 4fc4d3e... Conflict test
Resolve all conflicts manually, mark them as resolved with
"git add/rm <conflicted_files>", then run "git rebase --continue".
You can instead skip this commit: run "git rebase --skip".
To abort and get back to the state before "git rebase", run "git rebase --abort".
Could not apply 4fc4d3e... Conflict test
CONFLICT (add/add): Merge conflict in R/conflict test.R
Auto-merging R/conflict test.R
How do I have a conflict? How can my local copy be behind if I am the only one working on this project?
To work around this I've started performing commits, then forcing the push via git push -f origin main. Since I am the only person who will ever work on this project, perhaps this is safe; however, it's obviously not recommended and shouldn't be needed.
Also, I went back to my previous packages and performed some test commits. Sure enough, I now have this same error when I try to push new commits to GitHub for packages that were communicating perfectly previously.
I have spent some time trying to figure this out, but my efforts are limited to trying to create the repo and local package in different ways and connecting them with SSH vs URL, etc. I'm not well versed in GitHub; once my previous projects were set up I just used the same protocol to commit and push (again, I am the only user editing any of these packages). My guess is that somehow my updates to R, RStudio, or git seem to have created some sort of communication issue that I can't figure out.

JGit does not pull the remote reset

I am seeing a strange behaviour, I don't know if it is a bug or a feature.
From machine #1 I do git reset --hard someCommit && git push -f. The reset is then propagated to all machine (I can see the change by doing a git pull or git logfrom another machine).
From machine #2 that runs JGit I perform: git.pull().call() but the reset is not applied and the files on disk are not changed. Also git.log().call() does not point to the reverted commit.
What am I doing wrong?
Like Tim described, you likely need to force fetch on the other computers.
The return value of PushCommand::call() will tell you if and why the push did not succeed.
To force pull in JGit, follow this example:
git.fetch()
.setForce( true )
.setRefSpec( new RefSpec( "refs/heads/someBranch:refs/remotes/origin/someBranch" ) )
.call();
git.reset()
.setMode( ResetType.HARD )
.setRef( "someBranch" )
.call();
I believe that the git.pull.call() command is being rejected. You executed the following commands:
git reset --hard someCommit
git push -f
The first one should completely reset the branch to someCommit. The second one force pushes the reset branch to the remote, rewriting the history of the branch in the process. The keyword here is -f which is short for --force.
Because you rewrote the history of this branch, other computers will no longer be able to do a simple git pull because the base of the branch has changed. So I believe that your JGIT call to git.pull().call() is failing with an error. To fix this, you need to "force" pull the branch on the other computers:
git fetch --all
git checkout someBranch
git reset --hard origin/someBranch

Errors when using RStudio's Git tools

When attempting to push to GitHub from RStudio, I get the following errors.
error: unable to read askpass response from 'rpostback-askpass'
fatal: could not read Username for 'https://github.com':
No such device or address
RStudio has my origin as
https://github.com/rmscriven/other.git
when it actually should be
https://github.com/rmscriven/saber.git
RStudio will not allow me to change the origin from the version control system. Here is what it shows:
Is it possible to change my GitHub origin url from RStudio?
Thanks to the pro tip provided by #krlmlr in the comments,
Use an empty target directory. Look for "clone URL" on your GitHub project page, perhaps choose the SSH variant.
I clicked "clone url" on GitHub once, nothing. Then again, nothing. And once again for good measure, nothing. So I went to the terminal, read the man git help file, and decided to change my password and reconfigure. These are the lines I ran, and it was successful.
git config --global user.name <myuser.name>
git config --global user.email <myuser.email>
git clone https://github.com/rmscriven/saber.git
git pull
Then I went to RStudio and it allowed me to clone my repository, and change the URL of my version control setting. Here's a colorful pic
New project -> Version Control -> Git -> Create Project
Next, magic happened, and I had a copy of my package which I very carefully removed to prepare to push the development tarball to GitHub. Rock on.
#krlmlr, I thank you for nudging me in the right direction. Now I feel like I'm actually doing it the right way. :)
And for fun, try saying 'rpostback-askpass' ten times fast.
I had the same problem and for me these two simple steps worked great:
Add the SSH key from RStudio to my github account.
Change the origin URL and use the -u flag for push/pull once (solution found here).
For 1., in RStudio go to Tools → Global Options... → Git/SVN → view public key, and copy the key. In your browser of choice, logged in on Github, click Edit Profile → SSH keys and paste the copied key here.
For 2., back in RStudio, click Tools → Shell… , then enter:
git remote add origin https://github.com/myname/test.git
git config remote.origin.url git#github.com:myname/test.git
git pull -u origin master
git push -u origin master
Of course, change "myname" to your username and "test.git" to the name of your project. (Or even "github.com" to the URL of your institute's github or similar.)
After doing this once, the Push/Pull buttons in RStudio should work and you don't need the shell anymore!
I've been running into this issue on multiple computers now, with a remote that doesn't support SSH and thus can't leverage password-less login.
The problem in this case is that by default, git ask for the password interactively, and RStudio can't display this graphically. The trick is to use git's credential storage system.
For instance on Mac OS X:
git config --global credential.helper osxkeychain
On Linux one could use the gnome-keyring integration.

Resources