forked from jennybc/happy-git-with-r
-
Notifications
You must be signed in to change notification settings - Fork 0
/
connect-troubleshooting.Rmd
159 lines (105 loc) · 6.75 KB
/
connect-troubleshooting.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
# RStudio, Git, GitHub Hell {#troubleshooting}
Problems we have seen and possible solutions.
If you experience some new problem and, especially, find the corresponding solution, [we'd love to hear from you!](https://github.com/jennybc/happy-git-with-r/issues)
## I think I have installed Git but damn if I can find it
When you install Git, try to control or record where it is being installed!
Make a mental or physical note of these things.
You may be able to find Git after the fact with these commands in the shell (Appendix \@ref(shell)):
* `which git` (Mac, Linux, or anything running a bash shell)
* `where git` (Windows, when not in a bash shell)
It is not entirely crazy to just re-install Git, using a method that leaves it in a more conventional location, and to pay very close attention to where it's being installed.
Live and learn.
## RStudio Git pane disappears on Mac OS
Sometimes the RStudio Git pane disappears on a system where it was previously working.
This usually happens to people who installed Git by installing the Xcode command line tools.
It is usually a sign that you need to re-agree to the Xcode license agreement. This is necessary after a Mac OS upgrade, re-installing Xcode, or even quiet Xcode upgrades that sometimes seem to happen without the user's knowledge.
In the shell, you could execute `git status` and you might see a message along these lines:
```console
Agreeing to the Xcode/iOS license requires admin privileges, please run “sudo xcodebuild -license” and then retry this command.
```
If you get such clear instructions, by all means do what it says, i.e. run `sudo xcodebuild -license`, to re-agree to the license.
In any case, you need to tickle the Xcode command line tools to prompt you for whatever it needs. Here are other commands that, depending on the situation, might trigger the necessary prompts:
```console
xcode-select --install
```
or
```console
git config --global --list
```
Then **restart RStudio**.
## Dysfunctional PATH
Some cases of RStudio *not* automatically detecting the Git executable stem from problems with `PATH`.
This is the set of directories where your computer will look for executables, such as Git (today) or `make`.
Certain methods of Git installation, especially on Windows and/or older OSes, have a higher tendency to put Git in an unconventional location or to fail to add the relevant directory to `PATH`.
How to see your `PATH`?
In the shell:
```console
echo $PATH
```
Take a good hard look at this.
See the point above about finding your Git executable or re-installing it while you are **wide awake**.
Is the Git executable's parent directory in your `PATH`?
No?
**Fix that.**
At this point I recommend that you do a Google search to find instructions on how to modify `PATH` on your specific operating system.
## Push/Pull buttons greyed out in RStudio
Are you sure your local repository is associated with a remote repository, e.g. a GitHub repo?
In a shell with working directory set to the local Git repo, enter this command:
```console
~/tmp/myrepo % git remote -v
origin [email protected]:jennybc/myrepo.git (fetch)
origin [email protected]:jennybc/myrepo.git (push)
```
We want to see that fetch and push are set to remote URLs that point to the remote repo.
If you discover you still need to set a remote, get the HTTPS or SSH URL, as appropriate, for your GitHub repo.
This is easy to get onto your clipboard from the repo's GitHub page.
Do this in the shell:
```console
git remote add origin https://github.com/jennybc/myrepo.git
```
Download all the files from the online GitHub repository and deal with any
conflicts (substituting `master` for `main`, if relevant).
```console
git pull origin main
```
Call `git remote -v` again.
Once you are satisfied that your GitHub remote is set properly, you can move on to the next step.
Are you sure the current branch is *tracking* a branch on the remote?
In that same shell, in your repo, do this:
```console
~/tmp/myrepo % git branch -vv
* main 2899c91 [origin/main] A commit from my local computer
```
The above shows successful confirmation that the local `main` branch is tracking `origin/main`, i.e. the `main` branch on GitHub.
If you don't see the `[origin/main]` bit, that is a problem.
By the way, `git branch -r` and `git remote show origin` are two more commands that are helpful for examining your remote setup.
When connecting a local repo to a new GitHub repo, a lot of people remember to add the GitHub remote, but forget to also cement this tracking relationship for any relevant branches.
If you discover your local `main` branch is not yet tracking `main` on GitHub, fix that like so:
```console
git push --set-upstream origin main
```
This is equivalent to `git push -u origin main` but conveys more about what you are doing.
Call `git branch -vv` or `git branch -r` or `git remote show origin` again to confirm that the `main` branch on GitHub is the tracking branch for the local `main` branch.
## I have no idea if my local repo and my remote repo are connected.
See the above section on "Push/Pull buttons greyed out in RStudio."
## Push rejected, i.e. fail at the Git/GitHub level
You might have changes on the remote AND on your local repo.
Just because you don't remember making any edits in the browser doesn't mean you didn't.
Humor me.
Pull first.
Resolve any conflicts.
Then try your push again.
## RStudio is not making certain files available for staging/committing
Do you have a space in your directory or file names? [A space in a file name is a space in your soul.](https://twitter.com/aaronquinlan/status/711593127551733761)
Get rid of it.
Is your Git repo / RStudio Project inside a folder that ... eventually rolls up to Google Drive, DropBox, Microsoft OneDrive, or a network drive?
If yes, I recommend you move the repo / Project into a plain old directory that lives directly on your computer and that is not managed by, e.g., Google Drive.
If you cannot deal with the two root causes identified above, then it is possible that a more powerful Git client (chapter \@ref(git-client)) will be able to cope with these situations.
But I make no promises.
You should also try Git operations from the command line.
## I hear you have some Git repo inside your Git repo
Do not create a Git repository inside another Git repository. Just don't.
If you have a genuine need for this, which is really rare, the proper way to do it is via [submodules](http://git-scm.com/book/en/v2/Git-Tools-Submodules).
In STAT 545, we certainly do not need to do this and when we've seen it, it's been a mistake.
This has resulted in the unexpected and complete loss of the inner Git repository.
To be sure, there was more going on here (cough, GitHub Desktop client), but non-standard usage of Git repos makes it much easier to make costly mistakes.