Using Git and GitHub with RStudio: : CHEATSHEET
Version control control, also known as source control, is the
practice of tracking and managing changes to software code.
Basics Undoing Changes
Version control systems are software tools that help software
teams manage changes to source code over time. git init <directory> Create empty Git repository git revert <commit> Create new commit that undoes all of
in specified directory. the changes made in <commit>, then
Git is an open-source software for version control, originally apply it to the current branch.
developed in 2005 by Linus Torvalds, the creator of the Linux git clone Clone a repository located
operating system kernel. <repository> at <repository> on your local machine. git reset <file> Remove <file> from the staging area
but leave the working directory
Git it is a version control tool to track the changes in the source unchanged. This unstages a file without
code of a project. git config user.name Define author name to be used for all
overwriting any changes.
<username> commits in current repository.
GitHub is the most popular hosting service for collaborating on git clean -n Shows which files would be removed
git add <directory> Stage all changes in <directory> for the
code using Git. from working directory. Use the –f flag
next commit.
in place of the –n flag to execute the
Requirements git commit -m
<"message">
Commit the staged snapshot, but
instead of launching a text editor, use
clean.
1. R and RStudio installed
2. Git installed
git status
<"message"> as the commit message.
List which files are staged, unstaged,
Rewriting Git History
3. Register a free GitHub account
and untracked.
git log Display the entire commit history using git commit --amend Replace the last commit with the
Check that Git is installed the default format. staged changes and last commit
git diff Show unstaged changes between your combined. Use with nothing staged to
In the Terminal of RStudio, enter which git to request the index and working directory. edit the last commit’s message.
path to your Git executable:
git rebase <base> Rebase the current branch onto
which git <base>. <base> can be a commit ID,
## /usr/bin/git branch name, a tag, or a relative
and git --version to see its version:
Remote Repositories reference to HEAD.
git reflog Show a log of changes to the local
git --version repository’s HEAD. Add --relative-date
## git version 2.34.1 git remote add Create a new connection to a remote flag to show date info or --all to show
<name> <url> repository. After adding a remote, you can all refs.
use <name> as a shortcut for <url> in other
Introduce yourself to Git commands.
Git Branches
git fetch <remote> Fetches a specific <branch>, from the
Open a shell from RStudio Tools > Shell and type each line <branch> repository. Leave off <branch> to fetch all
separately by substituting your name and the email remote refs.
associated with your GitHub account: git branch List all of the branches in your repo.
git pull <remote> Fetch the specified remote’s copy of Add a <branch> argument to create a
git config --global user.name 'Jane Doe'
current branch and immediately merge it new branch with the name <branch>.
git config --global user.email
'
[email protected]' into the local copy. git checkout –b Create and check out a new named
git push <remote> Push the branch to <remote>, along with <branch> <branch>. Drop the –b flag to checkout
Github Glossary <branch> necessary commits and objects. Creates
named branch in the remote repository if it
an existing branch.
git merge <branch> Merge <branch> into the current
This glossary introduces common Git and GitHub terminology. doesn’t exist.
branch.
RStudio® is a trademark of RStudio, Inc. • CC BY SA Mouna Belaid • [email protected] • mounabelaid.netlify.app • Learn more at Happy Git and Github for the useR • Updated: 2022-01