Setting up a GitHub account
If you have not already, make sure you have created an account on
GitHub here and are added to the anyone-can-cook
organization.
Installing Git for Macs
Mac users should already have git installed. Open up your Terminal
application and check that it is installed by running
git
. You should see some information about Git commands and
usage being outputted to your screen.
If not, then you may need to install Git by downloading it from here.
Installing Git for Windows
What is Git for Windows?
- Since Bash is not the default shell on Windows (unlike macOS), it
must be installed. One way is by downloading Git for Windows, which comes with
Git Bash.
- “Git Bash is a package that installs Bash, some common bash
utilities, and Git on a Windows operating system.”
- Specifically, this installation comes with executables that RStudio
can find and use to make it possible to run Git and Bash commands in an
RMarkdown code chunk.
Steps to install:
- Download Git for Windows
and run the installer
- note: screens on installation steps will look slightly
different for you because below screens based on an older version of
Git
- One of the first screens you’ll see in the setup process is the
location where Git will be installed (e.g.,
C:\Program Files\Git
). Leave it as default but just make a
note of this path in case we need it later for troubleshooting purposes.
- In the screen below, you can optionally select to install a shortcut
to Git Bash on your Desktop for easier access.
- When asked about which default editor you would like Git to use, go
with the option that is already pre-selected for you (i.e., Vim)
- if you have a preferred text editor already installed, feel free to
choose that instead
- for most of the remaining installation steps, go with the
pre-selected (default) options except a couple steps described
belowr
- Adjusting the name of the initial branch in new
repositories
- choose the option Override the default branch name for new
repositories and make sure new branch name set to
main
- When you get to the step shown below about Adjusting your
PATH environment, make sure to select Use Git and
optional Unix tools from the Command Prompt. If you do not, you
may run into the issue described in the troubleshooting section below.
- After you finish the installation process, check that Git
Bash is your default terminal in RStudio by
going under
Tools
> Global Options...
(Terminal
tab). You may need to restart
RStudio for changes to be reflected.
Troubleshooting
PATH
environment variable:
- If you are not able to run Bash in an RMarkdown code chunk after
installing Git for Windows, it may be because RStudio is not able to
locate the necessary executables since its directory is not in your
PATH
environment variable
- “[
PATH
] specifies the directories in which executable
programs are located on the machine that can be started without knowing
and typing the whole path to the file on the command line.”
Adding to PATH
on Windows:
- You can run R code to check if the Bash executable is in your
PATH
Sys.which('bash')
: Path to your Bash executable (e.g.,
C:\Program Files\Git\bin
)
Sys.getenv('PATH')
: PATH
environment
variable containing list of paths separated by ;
that your
machine knows to look for
- If the path to your Bash executable is not part of your
PATH
, you can add it
- One way to do it is by running the R command
Sys.setenv()
seen here,
but this only modifies the PATH
for your current R
session
- Instead, you can follow these
steps to add
C:\Program Files\Git\bin
to your
PATH
Running bash in RMarkdown
Check that you are able to run bash in an RMarkdown code chunk:
- Create a new RMarkdown file
- Add a code chunk and indicate
{bash}
, as seen
below
- Run
echo "Hello, World!"
inside the code chunk and make
sure it works
Generating GitHub access token
What are local and remote
repositories?
- Local vs. remote git repository:
- Local git repository: Git repository for a project
stored on your machine
- Remote git repository: Git repository for a project
stored on the internet (e.g., GitHub)
- Typically, a local git repository is connected to a remote git
repository for collaboration
- A remote repository is identified by its URL, which can be used to
connect your local repository
- There are 2 types of URL: HTTPS and SSH
- HTTPS and SSH are two different ways to authenticate that you are
you
- If you haven’t set up SSH, then choose HTTPS (you will most likely
be using this)
Steps to set up access token:
- If you are using HTTPS, you must first create a
personal access token on GitHub following these
instructions
- “Once you have a token, you can enter it instead of your password
when performing Git operations over HTTPS.” (GitHub
Docs)
Tutorials [optional]
- Codecademy tutorial (10-20 min read)
- Hello World GitHub Guide (10-20 min read)