Learning Git

Josiah Baker & Steve Mortimer
November 1, 2016

Installing git

  • Instructions for installing on all platforms (Linux, Mac, Windows) are available here:
    https://git-scm.com/book/en/v2/Getting-Started-Installing-Git
  • You can verify that your installation worked by checking the version of Git from the command line.
    • Mac Users: Open up your terminal
    • Windows Users: Open up Git Bash
    • Run the following command:
git --version

Generating Your SSH Key

  • Check for existing keys
    ls -al ~/.ssh
  • If you don’t have keys, then generate a key
    ssh-keygen -t rsa -b 4096 -C “YourEmail@mail.com”
  • Start the key agent
    eval “$(ssh-agent -s)”
  • Add the key to the agent
    ssh-add ~/.ssh/id_rsa

Copy Public Half of SSH Key to GitHub

  • Log into GitHub -> Settings -> SSH and GPG keys
  • Copy the key to clipboard and Paste
    • Mac Users
      pbcopy < ~/.ssh/id_rsa.pub
    • Windows Users
      cat ~/.ssh/id_rsa.pub > /dev/clipboard

Working on Branches + a Pull Request

  • Start work on a “branch”. It’s a copy of your current state
    git checkout -b my_branch
  • This branch is only local, so push it to GitHub
    git push -u origin my_branch
  • Make a change to the README.md file, commit, & push
  • Next switch back to master branch and look at README.md
  • git checkout master
  • Your change is gone! It only exists on “my_branch”. Switch back now
  • git checkout my_branch

Branching + Pull Request

  • Branches isolate code until ready to be “merged”
    Create a pull request when you are ready to merge
    • Look in GitHub for “my_branch”
    • Click the button that says “Compare & pull request”
  • Pick a “target” branch (where you want new code to be applied)
  • Review that your changes make sense
  • Add a message outlining why this pull request is needed and how it essentially solves the problem of why it was needed

Items Still Not Covered

  • Stashing work with git stash and git stash pop
  • More advanced branching with git checkout
  • Forking and staying current with git rebase
  • Closing issues via commit messages (more info here)
  • Other ways to fix or undo your git history (more info here)
  • Git LFS (Large File Store) for versioning large data files