Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windows: "bash: git: command not found" error thrown in RStudio shell, but not in Git Bash #67

Closed
everettttt opened this issue Nov 3, 2017 · 22 comments

Comments

@everettttt
Copy link

@everettttt everettttt commented Nov 3, 2017

tl;dr, In the book, can you consider telling Windows users to select "Use Git from the Windows Command Prompt" when installing Git? I believe it prevents the following headache.


I ran into the error described here. My scenario:

  • Windows 10 (64-bit). Had latest versions of R ("short summer") and RStudio (1.1.383).
  • Had latest version of Git from here.
  • Running which git in Git Bash returned the git.exe location.
  • I was able to run all git commands in Git Bash with no errors. Could set username and email.
  • I then opened an existing R project already under version control in RStudio ("Git" menu was visible).
  • Running which git gave a really long error message.
  • Running git --version and git config --global --list threw the error, bash: git: command not found.
  • I confirmed that "Version control system:" in Tools > Project Options > Git/SVN was set to "Git".
  • I confirmed that "Git executable" in Tools > Global Options > Git/SVN was set to the same exact path as shown by running which git in Git Bash.
  • I confirmed that the “Use Git Bash as shell for Git projects” box in Tools > Global Options > Git/SVN was ticked. Edit: This option is not in RStudio v1.1.383. My confusion.
  • Name of the Rstudio git shell window was MSYS, not cmd.exe nor MINGW64, as you warned in the book here.

My resolution:

  • Re-installed git from here (did not uninstall).
  • During installation, selected "Use Git from the Windows Command Prompt" (different from default). Left all other options throughout the installation at their default settings.
  • Running git config --global --list in Git Bash showed my same username and email. No need to reset.
  • Running which git in RStudio's shell returned the git.exe location.
  • All git commands work in RStudio's shell now.
  • Am able to set username and email in RStudio's shell.

Perhaps this is worth noting in the book? A good spot would be under section 8.1 here, since related notes for Windows users are already there.

@jennybc
Copy link
Owner

@jennybc jennybc commented Nov 3, 2017

Would you like to make a PR for this? This is the kind of practical detail I definitely want to capture here and Windows is not my OS.

cc @daattali @kevinushey (does this all sound right to you?)

@daattali
Copy link
Contributor

@daattali daattali commented Nov 3, 2017

Definitely really useful to have there. I usually love helping you but I'm out of commission on non essential items for the next few weeks, sorry!

💩
🎉

( ^ sorry to be a party pooper)

@kevinushey
Copy link

@kevinushey kevinushey commented Nov 3, 2017

@everetr: Can you confirm that you are indeed running with RStudio v1.1.383? Normally, the git shell itself places extra utilities on the PATH. Do you by any chance have a startup profile / script that modifies the PATH? For posterity, I see:

screen shot 2017-11-03 at 4 08 00 pm

In addition, this:

I confirmed that the “Use Git Bash as shell for Git projects” box in Tools > Global Options > Git/SVN was ticked.

We actually removed that option from v1.1.383, as users found it confusing that the type of shell launched differed between Git projects and non-Git projects. Now, we always launch a shell matching the one selected in the Tools -> Global Options -> Terminal pane, e.g.

screen shot 2017-11-03 at 4 10 25 pm

I'd also be curious to see what the output of echo $PATH | tr ':' '\n' is in the shell launched by RStudio; e.g. I have:

kevin@DESKTOP-KLBFU53 MSYS /c/Users/kevin/Documents
$ echo $PATH | tr ':' '\n'
/c/Users/kevin/Documents/=/bin
/usr/local/bin
/usr/bin
/bin
/opt/bin
/c/R/R-3.4.2patched/bin/i386
/c/ProgramData/Oracle/Java/javapath
/c/WINDOWS/system32
/c/WINDOWS
/c/WINDOWS/System32/Wbem
/c/WINDOWS/System32/WindowsPowerShell/v1.0
/c/Program Files/MiKTeX 2.9/miktex/bin/x64
/c/Program Files (x86)/Windows Kits/10/Windows Performance Toolkit
/c/Users/kevin/AppData/Local/Microsoft/WindowsApps
/c/Program Files/CMake/bin
/c/Program Files (x86)/WinAnt/bin
/cmd
/c/Program Files/RStudio/bin/msys-ssh-1000-18
/usr/bin/vendor_perl
/usr/bin/core_perl

Note the entry called /cmd.

@everettttt
Copy link
Author

@everettttt everettttt commented Nov 3, 2017

@kevinushey

My mistake. “Use Git Bash as shell for Git projects” is in section 8.1 of the book. I did NOT confirm that that box was checked, because it's not in my RStudio.

I'll try to recreate this error and send you screenshots and the output of echo $PATH | tr ':' '\n'

@krshedd
Copy link

@krshedd krshedd commented Nov 10, 2017

I was updating my version of RStudio and Git today and had the exact same issue described by @everetr. His resolution (re-installed with "Use Git from the Windows Command Prompt") worked for me as well. Thanks for posting.

@jennybc
Copy link
Owner

@jennybc jennybc commented Nov 11, 2017

Ha! I set up a Windows VM last night and made sure to select this myself. It was selected by default for me ... at least I think so. But it sounds like we need to repeat or move this advice, yes?

@everettttt
Copy link
Author

@everettttt everettttt commented Nov 13, 2017

Just re-download Git (did not uninstall) and reproduced the error described in OP.

Installation settings:

image

image

image

image

image

image

Output of which git in Git Bash:

image

Output of which git in RStudio Shell:

image

Output of git --version in Git Bash:

image

Output of git --version in RStudio Shell:

image

Output of git config --global --list in Git Bash:

image

Output of git config --global --list in RStudio Shell:

image

RStudio Version:

image


Git path set correctly in Global Options.


Output of @kevinushey's requested command in RStudio Shell:

image

Reinstalling, the only option I change is:

image

Output of commands in RStudio Shell after that reinstall:

image


@jennybc The "Use Git from Windows Command Prompt" was not selected by default during my first installation. It was selected by default only if I tried reinstalling Git after having already installed Git with that option selected (if that makes sense).

@kevinushey
Copy link

@kevinushey kevinushey commented Nov 13, 2017

Thanks for following up! I'll have to re-test this -- I am pretty sure in my case that the default behavior in the installer was to select "Use Git from the Command Prompt", but it seems as though that's not true in general. Even so, we should make sure that Git integration works even if that option is not selected.

@everettttt
Copy link
Author

@everettttt everettttt commented Nov 13, 2017

I will make a PR to note this in section 8.1 of the book.

@jennybc
Copy link
Owner

@jennybc jennybc commented Nov 13, 2017

Thanks @everetr!. Should it go in http://happygitwithr.com/install-git.html#windows? Because seems like a fact that is good to know at Git install time.

@everettttt
Copy link
Author

@everettttt everettttt commented Nov 13, 2017

@jennybc You're right. Thanks! Will do.

@jennybc
Copy link
Owner

@jennybc jennybc commented Nov 14, 2017

Closed via 6f8ec67

@jennybc jennybc closed this as completed Nov 14, 2017
@Igneous01
Copy link

@Igneous01 Igneous01 commented Dec 7, 2017

Hi, I just installed git using the exact same settings as OP and I get the same issue:

image

I tried OPs suggestion and reinstalled (checking use git from windows command prompt option) but it still does not work.

I'm not able to get Git CMD Working either (Although maybe I dont understand the difference between GitCMD and Git Bash):

image

Adrianf23 added a commit to Adrianf23/happy-git-with-r that referenced this issue Jan 8, 2018
The screenshot is outdated. 

As of RStudio v1.1.383, there is no option to  "Use Git Bash as shell for Git projects". There was an issue with opening Git Bash as the default terminal for RStudio on a Windows machine (as opposed to Command Prompt). This forum cleared up the issue: jennybc#67.
@melindahiggins2000
Copy link

@melindahiggins2000 melindahiggins2000 commented Jan 8, 2018

Thank you all for this issue post. I just ran into this issue on a new Windows computer (had to get my old one repaired), so I'm setting everything back up. I'm glad to get the terminal working so I can teach my students this new awesome feature of RStudio this semester!

@arnold-c
Copy link

@arnold-c arnold-c commented Jan 14, 2019

Thanks very much to those who put together this excellent resource. I'm afraid that I, unfortunately, am having issues with Git within RStudio, and was wondering if anyone had a bright idea for the solution? Initially, it was working with my repos, and then one day they started to show the error "RStudio, directory name is invalid".

I am using W10, RStudio 1.1.463, git version 2.19.1.windows.1

I have tried the solutions to previous similar questions (repo paths do not contain non-ASCII char). I can use git with SourceTree, so I don't think it's an issue with my git version.

When I try to commit/pull/push changes it just shows "RStudio, directory name is invalid" and does not allow me to perform any git commands. Also, when I look at the git viewer in RStudio, it is just blank/white, whereas it would usually allow me to stage files etc.

In an attempt to try and fix the issue, I uninstalled and reinstalled git, following the steps above. Whilst git works perfectly well with SourceTree and in the command line, RStudio is not able to find it i.e. in creating a VCS project it returns "Git was not detected on the system path". However, I have placed C:\Program Files\Git\bin\ in the system path via environment variables. I have also set the git executable path in RStudio's global options as C:/Program Files/Git/bin/git.exe.

Any help would be appreciated, as whilst it's not essential, it would be nice to get working again

@kevinushey
Copy link

@kevinushey kevinushey commented Jan 14, 2019

@arnold-c are you attempting to use git with a project that's located on a network drive by any chance? (What is the output of getwd() in your project?)

@arnold-c
Copy link

@arnold-c arnold-c commented Jan 14, 2019

@kevinushey No, it's on my laptop's C: Drive (getwd() outputs C:/Users/owner/Documents/Repos/rti).

@kevinushey
Copy link

@kevinushey kevinushey commented Jan 14, 2019

Interesting. Would you mind filing this as a bug report at https://github.com/rstudio/rstudio/issues?

A diagnostics report may be helpful as well.

@everettttt
Copy link
Author

@everettttt everettttt commented Jan 14, 2019

@kevinushey Sidenote: Are there known issues with using Git+RStudio on a network drive? Is this Windows-specific?

@arnold-c
Copy link

@arnold-c arnold-c commented Jan 14, 2019

@kevinushey Thanks for your help. I've submitted a bug report and referenced this discussion.

@kevinushey
Copy link

@kevinushey kevinushey commented Jan 14, 2019

@everetr On Windows specifically, we've seen some issues when using Git from RStudio within a project that lives on a network path referenced with a UNC path (e.g. \\server\path). One can workaround the issue by mapping the network path to a local drive, but that's kind of a kludge.

@lunatic-fringe566
Copy link

@lunatic-fringe566 lunatic-fringe566 commented Jun 4, 2021

I'm stuck on a beginner problem of using git please a little Help is really appreciated I'm stuck on this for many days😟. So Whenever I create a new folder (For ex: repo) and on doing pwd (i.e., repo pwd ) even on changing directory (i.e., cd repo) it still always shows "command not found"
please help......!!🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants