Compartmentalized | Documented | Extendible | Reproducible | Robust |
Git A program to track your file changes and create a history of those changes. Creates a ‘container’ for a set of files called a repository.
GitHub A website to host these repositories and allow you to sync local copies (on your computer) to the website. Lots of functionality built on top of this.
.git
(so if you wanted to get rid of the history and other Git info, you could delete that folder). You have a local repo and a remote repo (on GitHub/GitLab).Today I will cover the basic Git/GitHub skills (and info) that are all most people need for 95% of their work. I am using GitHub Desktop. 1 If you want to use Git from RStudio, go to set-up and scroll to the section on RStudio and Git.
Simple Workflow:
We’ll do this
Not this, i.e. what you would see if you Google “Git”.
Jump to this part of the video
Repository skills (using GitHub Desktop)
Skill 1: Create a blank repo on GitHub
Skill 2: Clone one of your GitHub repos onto your computer
Skill 0: Open your repository in your editing platform. I am going to use RStudio, but you use whatever you edit in.
Skill 3: Commit local changes
Skill 4: Push local changes GitHub
Skill 1b: How to clone someone else’s GitHub repository
# Let’s see it done!
See Set-up
Jump to this part of the video
Jump to this part of the video
https://www.github.com/yourname/yourrepo
This is just for RStudio users. Others can ignore this step.
New Project
.Existing Directory
and navigate to the directory where you just saved the repo.Jump to this part of the video
Jump to this part of the video
You can clone your own or other people’s repos.
+
in top right and click import repository
. Paste in the url and give your repo a name.Let say you want to make a copy of one of your GitHub repositories and use it as a template to make something brand new.
Note there are some easier ways to do this but the above is how to do it with your skills 1-3.
Forking is if you are contributing to someone else’s repository. In that case, you need to make ‘pull requests’. Pull request = ‘here is a suggested change’ request.
Cloning is if you want your own copy of the repository because you want to make your own version of the code or use it as a starting point for your own project. Or you need to clone a blank repository to get started on a project.
Merge conflicts happen when there are changes to a file on your remote repository (GitHub) but also changes to that same file on your local repository. Git doesn’t know how to resolve the conflicting changes and needs your help. GitHub Desktop will warn you and give you some helpful options to resolve these.
A copy of your repository that you can work on without changing the main repository. Once you are done, you incorporate the changes into the main repository. Most of you should steer clear of branches because they are incompatible with our common workflows!! I maintain many repositories and use branches on only 2 of them.
FAQ
Why GitHub Desktop? I teach using it because it is made by GitHub and all you have to do is download and login with your GitHub account. No hassles for students. Also it is not specific to RStudio or JupyterLab which my students might not use. I use it in my personal work because my Git and GitHub work is simply much faster using it. I have many GitHub repos so speed and being able to track multiple repos is important to me. Also I use GitHub issues to plan and track my work. Being able to type ‘#’ in my commit message and see what issues are open on GitHub is critical for my workflow. Other people use RStudio’s Git GUI but it doesn’t have the functions I need. I also like GitKrakken. Search around and find something that works for your purposes. In JupyterLab I use the jupyter-git extension.↩︎