Git.. GitHub.. What are they? Why do they matter? In this tutorial we will introduce you to them and provide you with the basics! This presentation is for individuals with limited knowledge on git and graphical user interfaces, although those with a robust background are more than welcome to drop some knowledge on us! From one novice git user to another, we will walk through it together.
Have you ever tried working on a project or a specific piece of code with a colleague but could not figure out what changes they made? Or have you ever overwritten your own code and had to rewrite the chunk from the beginning?
Frustrating, right? Well, git is a version control that allows you to do better. Be a better coder, communicator and person because the time you will save can then be spent elsewhere!
Let’s get started shall we!
First, check to see if you already have Git installed.
On Windows, look for an application called “Git Bash” and on Macs, search for an application called “Terminal.” Type “git version” into the terminal. If you receive a version number, Git is installed. However, if the terminal is saying unknown command, then Git it not installed.
No Git? No problem. Navigate to git and click Downloads. Select the software appropriate for your system and follow the remaining installation steps.
Windows
Mac
If you have Git installed, then we will most likely just need to update it. To update git follow this video!
Otherwise, to install git:
When you configure git you will have options on what level you would like to make configurations.
System Level: git config --system
User Level: git config --global
Project Level: git config
Let’s set up some basic git configurations for our system.
For other configuration options see here.
Are you stuck? Ask Git! In the terminal, type “git help” and it will return some common Git commands. If you want to learn more about a specific command such as branching, you can type “git help branch” and it will pull up a manual on branching.
Git but better. Graphical User Interfaces (GUIs) are where you can use Git but in a more visually pleasing manner. Instead of using command lines in Git, you can use a click-based GUI. Think of it like using R/SAS versus SPSS or Jasp.
Microsoft | Mac |
---|---|
GitHub Desktop | GitHub Desktop |
GitKraken | GitKraken |
Sourcetree | Sourcetree |
TortoiseGit | Fork |
SmartGit |
GitHub makes it easier on us as human beings! GitHub is a cloud based management tool for your code. Think of it like Google Docs’ tracked changes feature. In any document, you can use tracked changes to visualize the changes you or someone else are making. In GitHub, we are using a similar way to visualize version control. This is extremely important when you start working in teams or on a large project. You will want to have changes to your code saved so that you can refer back if you need to.
Navigate here to download GitHub Desktop and follow prompts.
Note: You will want to create an account and hold on to the email you use for this account.
library(usethis)
You should have the latest version of R and Rstudio downloaded. To check your current version of R:
R.version.string
#> [1] "R version 4.0.5 (2021-03-31)"
You will also want to have git installed at this point. To introduce yourself to git using RStudio:
use_git_config(user.name = "Michelle Slawinski", user.email = "slawinsm@gmail.com")
#use.email should be the same as your GitHub account
To configure GitHub with RStudio, you will need to set up a token in RStudio. This is basically a secure connection between GitHub and RStudio:
usethis::create_github_token()
#> * Call `gitcreds::gitcreds_set()` to register this token in the local Git credential store
#> It is also a great idea to store this token in any password-management software that you use
#> * Open URL 'https://github.com/settings/tokens/new?scopes=repo,user,gist,workflow&description=DESCRIBE THE TOKEN\'S USE CASE'
gitcreds::gitcreds_set
#> function (url = "https://github.com")
#> {
#> if (!is_interactive()) {
#> throw(new_error("gitcreds_not_interactive_error", message = "`gitcreds_set()` only works in interactive sessions"))
#> }
#> stopifnot(is_string(url), has_no_newline(url))
#> check_for_git()
#> current <- tryCatch(gitcreds_get(url, use_cache = FALSE,
#> set_cache = FALSE), gitcreds_no_credentials = function(e) NULL)
#> if (!is.null(current)) {
#> gitcreds_set_replace(url, current)
#> }
#> else {
#> gitcreds_set_new(url)
#> }
#> msg("-> Removing credetials from cache...")
#> gitcreds_delete_cache(gitcreds_cache_envvar(url))
#> msg("-> Done.")
#> invisible()
#> }
#> <bytecode: 0x0000000015c1e568>
#> <environment: 0x0000000015bbacb0>
Term | Definition |
---|---|
Shell | A terminal that uses written commands to interact with your operating system |
Git Directory | Umbrella terms for all of your files and folders |
Modify | Changed the file but have not committed it to your local system |
Staged/Indexed | Marked a modified file to go into your next commit snapshot |
Commit | Save the state of your project in your local system |
Branch | When you duplicate part of a repository |
Merge | After you finish updating the code you branched, you can merge it back into the project’s main source code |
Push | Once you commit your project or file to your local system, you have the option to push it to remote GitHub |
Pull | If your repository has new changes in GitHub, you can download and integrate those remote changes by using ‘pull’ |
Fetch | To see if there are remote changes, you can use fetch to see what was updated. Fetch will not merge your updates though |
Now that you have an understanding of Git and GUIs such as GitHub, let’s practice!
We will be practicing how to fork a repository from GitHub, make a change locally, then commit those changes and push them back to GitHub. Ready? Lets get our feet wet.
& that’s it!