GitHub in GEN242
- Note, this class will make heavy use of GitHub
- Homework assignments will be submitted to private GitHub repositories: one repository for each student
- Course projects will also use private GitHub repositories: one repository for each course project (shared among students of each project)
- Each student will need a personal GitHub account. They can be created here.
- GitHub provides an unlimited number of free public repositories to each user. Via GitHub Education students can sign up for free private GitHub accounts (see here).
- All private GitHub accounts required for this class will be provided by the instructor via GitHub Classroom
- For beginners this quick guide may be useful
What are Git and GitHub?
- Git is a distributed version control system similar to SVN
- GitHub is an online social coding service based on Git
- Combined Git/GitHub: environment for version control and social coding
- Install on Windows, OS X and Linux
- When using it from RStudio, it needs to find the Git executable
Git Basics from Command-Line
Also try interactive git tutorial.
Finding help from command-line
git <command> --help
Initialize a directory as a Git repository
Add specific files to Git repository (staging area)
git add myfile
Add all files recursively
To ignore specific files (e.g. temp files), list them in a
.gitignorefile in your repository’s root directory. Regular expressions are supported. See here for more details.
git add -A :/
After editing file(s) in your repos, record a snapshot of the staging area
git commit -am "some edits"
GitHub Basics from Command-Line
Generate a new remote repository on GitHub online or use hub command-line wrapper for this. To avoid errors with the online method, do not initialize the new repository with README, license, or
.gitignorefiles. You can add these files after your project has been pushed to GitHub.
git remote add origin https://github.com/<user_name>/<repos_name>.git
Push updates to remote. Next time one can just use
git push -u origin master
Clone existing remote repository
git clone https://github.com/<user_name>/<repos_name>.git
Before working on project, update local git repos
Make changes and recommit local to remote
git commit -am "some edits"; git push -u origin master
Run the following git/github excercise from the command-line.
git clone https://github.com/<user or org>/<repo name> cd <repo name> git pull touch test # Creates empty file for testing git add -A git commit -am "some edits" git push -u origin master ##-> Edit test file online and then run `git pull` to inspect changes
Online file upload
This could be useful for new users who want to upload their homework assignments to GitHub but are not familiar enough with the command-line yet.
Create new filebutton on your repository.
- Under the file path window add required subdirectory structure and a dummy file name (e.g.
- After this press
Upload filesand upload any file (e.g. homework) to the newly create directory. After this the initial dummy file can be deleted. The latter is necessary since empty directories are not visible on GitHub.
Using GitHub from RStudio
- After installing Git (see here), set path to Git executable in Rstudio:
If needed, log in to GitHub account and create repository. Use option
Initialize this repository with a README.
- Clone repository by copying & pasting URL from repository into RStudio’s ‘Clone Git Repository’ window:
- Now do some work (e.g. add an R script), commit and push changes as follows:
Check files in staging area and press
To commit changes to GitHub, press
Shortcuts to automate above routines are here
- To resolve password issues, follow instructions here.