Cannot launch git from the terminal

Hi, all,

I have a very weird problem: I can clone from GitHub in RStudio (and I can probably push too, even though I haven't checked today), but I cannot run git in the RStudio terminal. I set up Git Bash as my terminal:

However, when I try to execute git in a terminal window, I get a command not found error:

This is a bit annoying because I prefer using Git from the command line, and also because because Git Bash allows me to do cool stuff such as diffing files which are not part of a Git repository. Can you help me? My configuration:

> sessionInfo()
R version 3.4.3 (2017-11-30)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)

Matrix products: default

locale:
[1] LC_COLLATE=Italian_Italy.1252  LC_CTYPE=Italian_Italy.1252   
[3] LC_MONETARY=Italian_Italy.1252 LC_NUMERIC=C                  
[5] LC_TIME=Italian_Italy.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] RevoUtils_10.0.7     RevoUtilsMath_10.0.1

loaded via a namespace (and not attached):
[1] compiler_3.4.3 tools_3.4.3    yaml_2.1.18   

Concerning Git Bash:

$ git --version
git version 2.16.2.windows.1

(of course this is what I get when running git --version in an actual Git Bash window outside RStudio).

PS another weirdness: when I open a shell in RStudio (not a terminal, though I'm not sure if they're actually different - it's in Tools/Shell...) I see MSYS in purple

but when I launch Git Bash from outside RStudio I see MINGW64 in purple

It's probably nothing important, just a different shell prompt, but I thought Git on Windows used MINGW64 (I don't know what MSYS is). @jennybryan as an expert in making RStudio coexist with Git, do you have any suggestions? :slight_smile:

Is git in your PATH ? check Sys.getenv("PATH") or test with devtools::on_path("git")

I think on some computer I had issue with git being installed locally but not add to PATH.

Windows is not my main OS but I have tried to capture best practices for Git/RStudio setup in Happy Git. Here's what we've settled on, based mostly on several years of STAT 545:

We recommend Git for Windows and selecting "Use Git from the Windows Command Prompt" during installation:
http://happygitwithr.com/install-git.html#install-git-windows

How to determine which Windows shell you are in and why and which one you want to be in:
http://happygitwithr.com/shell.html#windows-shell-hell

3 Likes

Hi @jennybryan, thanks for replying! Uninstalling RStudio and Git and reinstalling Git first, selecting "Use Git from the Windows Command Prompt"

and then installing RStudio, solved the issue for me. Thanks!

PS I successfully struggled with getting multiple accounts to co-exist smoothly in Git for Windows. If that's something that could be of interest for the happygitwithr.com audience, I can summarize my experience in a .Rmd file.

1 Like

Great! That probably is addressing a PATH issue, as also raised by @cderv.

Sure, I'd love a report on your successful struggle with multiple accounts. An issue on Happy Git would be the perfect place for it. Thanks in advance.

1 Like

Yes I think it does. The option with Git bash only works on windows (I have that one set) but it seems that RStudio Terminal needs git in the PATH (that is not done by the installer). It works well on my Windows computer but I have git folder in my PATH.

1 Like