These notes were made whilst going through Jenny Bryan’s Happy Git and GitHub for the useR instructions.
Register a GitHub account.
Turn on two-factor authentication under: Settings - Account security.
Install Git which can be done through Git for Windows.
Optionally install a Git client, for example GitHub Desktop, or other recommended clients.
In R Studio change terminal to open with Git Bash: Tools - Global Options - Terminal - New terminals open with - Git Bash.
Check Git installed on local machine
Git commands
where git
git --version
usethis::use_git_config set Git user name and email
usethis::use_git_config(user.name = "USERNAME", user.email = "EMAIL")
Check Git user name and email details
Git commands
git config --global --list
RStudio Tools - Global Options - Git/SVN - Git executable: set path, eg C:/Program Files/Git/bin/git.exe. Ensure Enable version control interface for RStudio projects is ticked.
Check for common issues and solutions in Jenny Bryan’s instructions.
usethis::create_github_token Get Personal access taken (PAT), storing token in a password management system
usethis::create_github_token()
gitcreds::gitcreds_set Store credentials in Git credential store
gitcreds::gitcreds_set()
usethis::create_from_github Clones a remote repository from GitHub, creating a local project and Git repository.
::create_from_github(repo_spec = HTTPS URL,
usethisdestdir = "DESTINATION DIRECTORY PATH"
fork = FALSE)
Git commands
git clone HTTPS URL
usethis::use_git Makes project a Git repository
usethis::use_git()
Git commands
git init
Git commands
git add -A
git commit -m "COMMIT MESSAGE"
git commit --amend --no-edit
usethis::use_github Create a new repository on GitHub
usethis::use_github()
Pull files from GitHub repository: RStudio Git - Pull button.
Push committed files to GitHub: RStudio Git - Push button.
Git commands
git pull
git push
Git commands
git branch BRANCH_NAME
git checkout BRANCH_NAME
Git commands
git checkout master
git merge BRANCH_NAME
Resolve merge conflicts, edit file either keeping contents of branch or master or modified version of both. Stage edited file and commit to master.
<<<<<<< branch contents =======
======= master contents >>>>>>>
Git commands
git status
git add EDITED_FILE_NAME
git commit -m "COMMIT MESSAGE"
-- If need to abort merge
git merge --abort
Git commands
git reset --hard HEAD
Git commands
git commit --amend -m "New commit message"
Git commands
-- revert to previous commit, saved and staged changes kept
git reset --soft HEAD^
-- revert to previous commut, saved changes kept but now unstaged
git reset HEAD^
-- revert to previous commit, saved and staged changes lost
git reset --hard HEAD^
In others remote repository on GitHub
In your repositories on GitHub
Git commands
git clone HTTPS URL
In others remote repository on GitHub (so that able to pull changes from other remote repository)
Git commands
git remote add upstream OTHERS REMOTE HTTPS URL
usethis::create_from_github Clones and forks others remote repository from GitHub, creating a copy of the repository on your account in Github, a local project and a Git repository, and adds the others remote repository as an upstream remote repository to allow pulling file changes from this upstream remote.
usethis::create_from_github(repo_spec = "HTTPS URL",
destdir = "DESTINATION DIRECTORY PATH",
fork = TRUE)
Git commands
git remote -v
Git commands
git pull upstream master --ff-only
git push
Git commands
git branch BRANCH_NAME
git checkout BRANCH_NAME
Only work on this branch, committing and pushing changes to the forked repository in your GitHub account
GitHub: Compare and pull request button - Create pull request to submit pull request to others remote repository