If you want to follow along with the presentations, you will need R, RStudio, a GitHub or GitLab account, and GitHub Desktop or Git+GitHub Desktop. Note GitHub Desktop works with both GitHub and GitLab and I will illustrate both.
Summary of the set-up steps. You can also consult this great online reference.
For the class, I am showing Git within RStudio, but it can be a real headache to get working for beginners. The following set-up is most likely to work.
I normally work with Git from GitHub Desktop only. It tends not to have the authentication headaches that Git in RStudio has. However, for the class I am going to work with Git from RStudio but I will also show GitHub Desktop. GitHub Desktop doesn’t have the authentication headaches that Git in RStudio has.
Next steps depend if you are a GitHub user or GitLab user:
GitHub: Login to GitHub from GitHub Desktop
GitLab:
To use both, do both sets of steps above.
GitHub If you are using GitHub in a work capacity, as opposed to purely non-work or school, then the repositories you post should be intended for public use (as opposed to just a personal repo). GitHub is officially allowed for a platform for release of products and provides a nice platform for that. I’ll show a few examples. There is paperwork to fill out info and checklist. Key point is that GitHub is not NOAA-controlled and sensitive information and data that needs to stay on government computers should not be on GitHub.
GitLab If you want to have repositories for work that is not intended for the public or that involve data, code, or reports that cannot be on a non-NOAA computer, then you can use the NWFSC GitLab server. Contact Marcus Nedelmann at NWFSC to get an account. No paperwork needed. Note it is easy to import back and forth between GitHub and GitLab.
If you don’t already have an account on GitHub, go to github.com and click the “sign up” link near upper right of the page. It is pretty self-explanatory. Go ahead and get a free account. The free GitHub account does not have private repositories. Everything is public and viewable. You can upgrade (for money) and get private repositories.
GitLab is quite similar to GitHub as a platform but is missing some of the nice features of creating a website for your repos. You can do it but just not as integrated. But GitLab’s free account gives you unlimited private repos.
git --version
. If it asks to install XCode, say Yes. Read notes hereGitHub Desktop is a nice Git interface for basic work. Despite the name, GitHub Desktop works just as well with GitLab.
If you are using GitLab:
R: Make sure you have a fairly recent version of R.
Go to CRAN and find the download link for your computer system. Those using a NOAA computer, contact IT to help you update/install.
RStudio: Install the latest version of RStudio. Get it from RStudio and install the appropriate one for your operating system (Windows or Mac). Again contact IT to help install if you are on a NOAA computer.
If you want to use Git within RStudio, do these steps. Note it is not necessary to use Git in RStudio. You can use GitHub Desktop (or any other Git GUI or the terminal command line).
Git executible
box is /usr/bin/git
. On my PC, it is C:/Program Files/Git/bin/git.exe
. If you install Git for Windows locally, it may be at C:\Users\your.username\AppData\Local\Programs\Git\bin\git.exe
.Tell Git how to get your username and password for GitHub/GitLab
git config --get credential.helper
manager
and if on a mac, osxkeychain
git config --global credential.helper osxkeychain
Windows: git config --global credential.helper manager
There is one more step that comes up on your first push to the remote. You’ll need to do your very first Push from the Shell within RStudio so that it knows your username and password.
Shell...
git push
In order to connect to GitLab, you will need to make an SSH key. GitLab will ask you for this. Note, I am not 100% sure GitLab actually needs this. If it let’s you, you can try skipping this.
Windows users: The txt file with the public token will be xxx.pub and Windows sees that as a MSPublisher file. Don’t double-click the file to open. Use Open With, and select a text editor.
ssh-keygen -t ed25519 -C "gitlab"
Can’t get Git, GitHub/GitLab, and RStudio to connect?
First off, can you get GitHub Desktop to work? If so, I would say just use that for awhile. You don’t need to use Git in RStudio.
If you want to use Git in RStudio, read on. You can also consult this great online resource.
There are two typical problems. 1. Git doesn’t know how to ask you for your username and password. 2. Your repo is pointing to the wrong GitHub/GitLab account. This can happen when you try to copy someone else’s account.
git config --global http.sslVerify false
RStudio doesn’t know where git.exe
is. First, have you installed Git yet?
If you are on Windows and you have not installed Git, install Git for Windows. Mac users should have it already. Mac It should be installed. Open a terminal window and type, git –version. If it asks to install XCode, say Yes.
Next, tell RStudio where to find git.exe
. You need to tell it under Tools > Global Options > Git/SVN > Git executible. On my mac the value in the Git executible
box is /usr/bin/git
. On my PC, it is C:/Program Files/Git/bin/git.exe
but IT installed it for me and installed for all users (so with admin). If you install Git for Windows locally (meaning you install it just for your account instead of for all users on your computer), it should be at C:\Users\your.username\AppData\Local\Programs\Git\bin\git.exe
You need to do a push from the terminal to store your username/password.
Shell...
git config --get credential.helper
and make sure you see manager
(or wincred
) if on Windows and osxkeychain
if on Mac.git
command to add those credential helpers.askpass
?RStudio doesn’t know how to open a terminal to ask for your username and password. You’ll need to push from the shell the first time.
So what’s going on is that Git (within RStudio) doesn’t know how to ask you for your GitHub username and password.
git config --list
. You should see credentials.helper=manager
(if on Windows) or credentials.helper=osxkeychain
(if on Mac). If not type, one of these commands. Mac: git config --global credential.helper osxkeychain
Windows: git config --global credential.helper manager
.git push
. You should be asked for your GitHub username and password.Git might have the wrong remote.
Shell...
git remote -v
and see if what is listed looks correct.git remote set-url origin URL
Replace URL
with the URL of your repository!!Windows people: You will need to install Rtools.
Run this code to confirm that you can install packages from GitHub:
devtools::install_github("RVerse-Tutorials/TestPackage")
To install from the gitlab.com
the command is similar. <gitlab account>
is a dummy. Replace with the real values.
devtools::install_gitlab("<gitlab account>/repo name")
To install from an internal GitLab server, like the NWFSC GitLab, use this. Note for the NWFSC GitLab, you need to be on the network since this is an internal (not public) server. Again, replace the dummy variables with the real values.
devtools::install_gitlab("<gitlab account>/repo name", host="<url of the server>")
We will not be doing this, but often you will want to install packages with C++ code. To do that, you will need Rtools (Windows) or Xcode (Mac)