2020.07.14

This slide presentation

What NOT to do (a.k.a. my dissertation)

A better git workflow

Why git?

Version control & collaboration

  • Version control is like an unlimited ‘undo’.
  • Version control also allows teams to work in parallel.
  • Primarily used for coding (python, R, sql, ), writing (markdown, latex, etc.), and many other formats

Reproducible code & public facing work

Work in parallel branches

  • Your master is your primary working version (e.g. 1.0)
  • When you want to make edits, you start a branch, make edits, then merge your work into the master

Caution:

  1. When working with team members, don’t work in the master, just in your branch.
  • You can easily cause conflicts between versions.
  1. Don’t store data in a repo
  • Github repositories have about a 2gb limit and you can’t push files bigger than 100mb at a time.

  • Instead, use Google Drive or Box

  • If you convert a private repo to a public one, all the history and data will become public.

Basic git principles

Before git

  • base version
  • make some edits
  • add more edits

Collaboration

Make edits in your branch, commit your edits to the repo, and push to your branch in Github

Collaboration

Then, make a pull request to merge your edits into the master

git workflow summary

  1. edit your file(s)
  2. commit your changes (a.k.a. staging)
  3. push to your branch on Github
  4. merge your final edits into the master through a pull request on Github.com

Activity 1

Activity #1: Create a git repository on your local machine and push it to Github using Github desktop

  1. Initialize a directory
  2. Edit a file
  3. Make a commit
  4. Publish to github
  5. Make a pull request (i.e. merge your edits to the master)

Summary of what we just did

  1. We made a repo
  2. We made some edits
  3. We staged the edits on our computer (add and commit edits)
  4. We pushed the edits onto Github.com

Add and Commit

Push to Github.com

Before we move on… some terminology

git terms

  • head = the tip of your current branch
    • e.g. the master branch or my “tim” branch
  • origin = the online head of the respective branch
    • you’ll notice that Github Desktop says “fetch origin”
  • fetch = tells your local git to retrieve the latest meta-data info from the original (yet doesn’t do any file transferring. It’s more like just checking to see if there are any changes available).
  • pull = on the other hand does that AND brings (copy) those changes from the remote repository (i.e. it merges the online changes to your local branch)

Activity 2

Activity 2: Clone a Github repo, make some edits, and merge it into the master

  1. Move your Github folder to your Home directory and rename it git
  2. Clone the repo https://github.com/timathomas/git_tutorial
  3. Make a branch
  4. Edit a file in the git_tutorial/code/ directory
  5. Commit your edits
  6. Publish to github
  7. Make a pull request

What you’ll be doing mostly during your projects

You’ll work in the master and work on your own python notebook (.ipynb)

  1. Edit
  2. Pull
  3. Stage
  4. Push

How to deal with merge conflicts

Some resources

My favorite tools

  • Sublime Text
    • Others Atom (sluggish in my opinion)
    • Favorite Sublime Packages
      • Git, Gitgutter, Thesaurus, LanguageTool, R-IDE, SendCode, Terminal
  • Sublime Merge to view complex branches