Working with Git and GitHub

Bullet-Proof Your Workflow

Created by Steven Bitner, PhD

What is Git?

It's not GitHub

It's just a program running on your machine

  • Creates hidden files under a directory called .git
  • Tracks status of your directory whenever you tell it to

Distributed Version Control System

  • Distributed, each clone of a repository can make changes directly, without an internet connection.
  • Version control
    • project2_v1.txt
    • project2_v2.txt
    • project2_final.txt
    • project2_final_v2.txt
    • project2_group_final.txt
    • project2_submitted.txt
    • project2_for_real_final_to submit.txt
    • project2_for_real_final_to submit_v2.txt

Going shopping

Present working directory - pwd

git add

git commit

git push

git pull

Git failed to push refs error message

What is GitHub

A cloud server cluster for collaborating

...and a bit more - pull requests, issue tracking etc.

Configs

First time user?

Global configs or GitHub will git angry

  • git config --global user.name "Your Name"
  • git config --global user.email "yourEmail@uwf.edu"

Initializing a repo

  • Ideally through cloning
    git clone https://github.com...
  • git init
    • Has extra overhead since you'll need to connect to a remote
    • git remote add origin https://github.com...

Development Cycle

A flowchart showing the standard development cycle in Git/GutHub
Meme to segue into more complicated topics

Git diff

Git Diff

Dang, it was just compiling a few minutes ago

Standard git diff showing changes made to the current repository

difftool

git config --global diff.tool vimdiff

Git diff using vimdiff

Remotes

  • git remote add origin https://github.com...
  • git remote add myPug https://foo.bar.com...
  • git remote add GoogleDrive\
       /Volumes/GoogleDrive/My Drive/repos/foo.git
    • First create a "bare" repo: git init --bare foo.git

Branches

What?

 Doc Brown shows alternate pasts int eh space time continuum

Why?

  • Broken code
  • New feature
  • Rapid rollback

How?

  • To create a branch: git checkout -b NEW_BRANCH_NAME
  • To get back to the previous branch, use its name, or : git checkout -
  • List all branches on your system: git branch

Merging and conflicts

  • git merge BRANCH_NAME
  • git merge -
  • Git isn't perfect, sometimes it can't automatically merge, so we get conflicts
  • Error output during a merge conflict

SSH

https://help.github.com/en/enterprise/2.15/user/articles/adding-a-new-ssh-key-to-your-github-account

Work-along is at

https://classroom.github.com/a/V3mtnZuo

GitHub Student Upgrade

https://education.github.com/pack

  • GitHub
  • Digital Ocean
  • AWS
  • Heroku
  • Stripe
  • Travis CI
  • A bunch more