The shell
(or bash
or terminal
) is a program on your computer whose job is to run other programs, rather than do calculations itself. The shell
is a very old program and in a time before the mouse it was the only way to interact with a computer. It is still extremely popular among programmers because it is very powerful, fast, and is particularly powerful at automating repetitive tasks.
Here we use the shell
for a more modest goal: To navigate the file system, confirm the present working directory, and cement the git
to GitHub
connection.
In RStudio, go to Tools > Shell. This should take you to the shell (on Mac: Terminal, on Windows: GitBash or equivalent). It should be a simple blinking cursor, waiting for input and looks similar to this (white text on black background, or black text on white background):
The most basic commands are listed below:
pwd
(print working directory). Shows the folder (or directory) you are currently operating in. This is not necessarily the same as the R
working directory you get from getwd()
.ls
(list all files). Shows all files in the current working directory. This is equivalent to looking at the files in your Finder/Explorer/File Manager. Use ls -a
to also list hidden files, such as .Rhistory
and .git
.cd
(change directory). Allows you to navigate through your folders by changing the shell’s working directory. You can navigate like so:
foo
of current working directory: cd foo
cd ..
cd ~
or simply cd
cd /home/my_username/Desktop
. Windows uses a slightly different syntax with the slashes between the folder names reversed, \
, e.g. cd C:\Users\MY_USERNAME\Desktop
.tab
key to autocomplete unambiguous folder and file names. Hit tab
twice to see all ambiguous options.CTRL
+r
.git status
is the most used git command and informs you of your current branch, any changes or untracked files, and whether you are in sync with your remotes.git remote -v
lists all remotes. Very useful for making sure git
knows about your remote and that the remote address is correct.git remote add origin GITHUB_URL
adds the remote GITHUB_URL
with nickname origin
.git remote set-url origin GITHUB_URL
changes the remote url of origin
to GITHUB_URL
. This way you can fix typos in the remote url.Go back to the index for the all the Git stuff.