git and GitHub

Acknowledgements

Parts of this presentation are based on these slides by Dr. Mine Çetinkaya-Rundel.

Today’s goals

  1. What is git?
  2. What is versioning?
  3. Local workflow of git
  4. What is GitHub?
  5. Local/remote workflow of git + GitHub
  6. Setting up git + GitHub workflows in RStudio
  7. Tips and resources

What is git?

Git logo

  • Git is a version control system – like “Track Changes” features from Microsoft Word, on steroids
  • It’s not the only version control system, but it’s a very popular one

Versioning

Versioning

with human readable messages

How does a git worflow look like in your local computer?

  1. Start a new git project typing in the terminal git init
  2. Create/modify folders and files inside of that git project directory
  3. Stage these changes typing in the terminal git stage -A
  4. Commit these staged changes typing in the terminal git commit -m "short yet informative message of changes made in this commit"
  5. Make more changes, repeat steps 3 and 4.

How does a git worflow look like in your local computer?

What is GitHub?

GitHub logo

  • GitHub is the home for your Git-based projects on the internet – like DropBox but much, much better

  • We will use GitHub as a platform for web hosting and collaboration (and as our course management system!)

Local/remote workflows of git + GitHub

1. No GitHub

2. GitHub clone (you own it)

3. GitHub clone (someone else owns, you are collaborator)

4. GitHub fork and clone (someone else owns, you are not collaborator)

Local/remote workflows of git + GitHub in this class

In this class, you will, for the most part, be working alone in GitHub repos that you own (option 2 from previous slide).

Local/remote workflow of git + GitHub we will use

After making sure your local git is connected to a GitHub repository through git clone:

  1. Follow same steps as for local workflow
  2. After committing changes, “upload” them to the GitHub repo typing in the terminal git push
  3. If there were any changes in the GitHub repo you did not have locally, “download” them to your local copy typing in the terminal git pull

Setting up git + GitHub workflows in RStudio

For that, we will follow the New project, GitHub first workflow (see link above for detailed instructions).

  1. Make a repo on GitHub
  2. New RStudio Project via git clone
  3. Make local changes, save, commit
  4. Push your local changes to GitHub

Setting up git + GitHub workflows in RStudio

Every single new coding exercise will follow the above workflow, in a way that you will have one git/GitHub repo in your own GitHub for each exercise.

git and GitHub tips

  • The workflows delineated above that include stage, commit, push, and pull are very simple.

  • git/GitHub can handle a lot more complex workflows including branching, forking, pull requests, etc.

  • For now, we will focus on the simple workflow above, and will explore more complex workflows as needed.

Wisdom notes

  • Commit often (multiple times a day), push less often (few times a day)

  • Before pushing, always pull first!

git and GitHub resources

Useful Git/Github terminal commands

git pull to start your work fresh with most recent version from remote
git status to check the status of git
git stage -A to stage changes
git commit -m "commitMessage" to make a commit
git push to send changes from local to remote
git log --oneline to see summarized list of commits (push q to quit console when done)

Now, let’s get all this going on your own laptops