Chapter 4 Connect to GitHub
Objective: make sure that you can pull from and push to GitHub from your computer.
4.1 Make a repo on GitHub
Go to https://github.com and make sure you are logged in.
Click green “New repository” button. Or, if you are on your own profile page, click on “Repositories”, then click the green “New” button.
Repository name: myrepo (or whatever you wish, we will delete this)
Public
YES Initialize this repository with a README
Click big green button “Create repository.”
Copy the HTTPS clone URL to your clipboard via the green “Clone or Download” button.
4.2 Clone the repo to your local computer
For the following steps use the RStudio in built terminal.
Take charge of – or at least notice! – what directory you’re in. pwd to display working directory. cd to move around. Personally, I would do this sort of thing in ~/tmp.
Clone myrepo from GitHub to your computer. This URL should have your GitHub username and the name of your practice repo. If your terminal cooperates, you should be able to paste the whole https://.... bit that we copied above. But some shells are not (immediately) clipboard aware. In that sad case, you must type it. Accurately.
git clone https://github.com/YOUR-USERNAME/YOUR-REPOSITORY.gitThis should look something like this:
tania@Mictlan tmp $ git clone https://github.com/trallard/myrepo.git
Cloning into 'myrepo'...
remote: Counting objects: 3, done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (3/3), done.
Checking connectivity... done.Make this new repo your working directory, list its files, display the README, and get some information on its connection to GitHub:
cd myrepo
ls
head README.md
git remote show originThis should look something like this:
tania@Mictlan~ $ cd myrepo
tania@Mictlan myrepo $ ls
README.md
tania@Mictlan myrepo $ head README.md
# myrepo
tutorial development
tania@Mictlan myrepo $ git remote show origin
* remote origin
Fetch URL: https://github.com/trallard/myrepo.git
Push URL: https://github.com/trallard/myrepo.git
HEAD branch: master
Remote branch:
master tracked
Local branch configured for 'git pull':
master merges with remote master
Local ref configured for 'git push':
master pushes to master (up to date)4.3 Make a local change, commit, and push
Add a line to README and verify that Git notices the change:
echo "A line I wrote on my local computer" >> README.md
git statusThis should look something like this:
tania@Mictlan myrepo $ echo "A line I wrote on my local computer" >> README.md
tania@Mictlan myrepo $ git status
On branch master
Your branch is up-to-date with 'origin/master'.
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: README.md
no changes added to commit (use "git add" and/or "git commit -a")Commit this change and push to your remote repo on GitHub. If you’re a new GitHub user, you will be challenged for your GitHub username and password. Provide them!
git add -A
git commit -m "A commit from my local computer"
git pushThe -m flag is an important message that must be included with every commit! Git requires a commit message for every commit, so if you forget the -m flag, git will prompt you for a commit message anyways. It is good practice to write meaningful commit messages so in the future, potential collaborators (and your future self) will understand the progression of a project.
This should look something like this:
tania@Mictlan myrepo $ git add -A
tania@Mictlan myrepo $ git commit -m "A commit from my local computer"
[master de669ba] A commit from my local computer
1 file changed, 1 insertion(+)
tania@Mictlan myrepo $ git push
Counting objects: 3, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 311 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To https://github.com/trallard/myrepo.git
b4112c5..de669ba master -> master4.4 Confirm the local change propagated to the GitHub remote
Go back to the browser. I assume we’re still viewing your new GitHub repo.
Refresh.
You should see the new “A line I wrote on my local computer” in the README.
If you click on “commits,” you should see one with the message “A commit from my local computer.”
If you have made it this far, you are ready to graduate to using Git and GitHub with RStudio (chapter 7). But first …
4.5 Am I really going to type GitHub username and password on each push?

It is likely that your first push, above, leads to a challenge for your GitHub username and password.
This will drive you crazy in the long-run and make you reluctant to push. Do one of the following to eliminate this annoyance:
Now is the perfect time to do this, since you have a functioning test repo.
4.6 Clean up
- Local: When you’re ready to clean up, you can delete the local repo any way you like. It’s just a regular directory on your computer.
Here’s how to do that in the shell, if current working directory is myrepo:
cd ..
rm -rf myrepo/- GitHub: In the browser, go to your repo’s landing page on GitHub. Click on “Settings”.
Scroll down, click on “delete repository,” and do as it asks.