Git

Keeping track of your work

Peter W. Smith

Follow along: https://pwsmith.github.io/reveal.js/git_tutorial.html

Version Control

Keeping a history

  • It's a good idea to keep a record of your work.
  • Something you write may be a bad idea.
  • So you get rid of it.
  • Then it turns out to be a good idea.
  • Then what?

Twists and turns of a crappy idea.

  • Best case scenario: you just commented it out.
  • Problem: you may have this a lot (I did) and your file becomes unreadable.

Twists and turns of a crappy idea

  • Middle case scenario: wary of delete, you start a new file.
  • Problem: you end up with a billion versions of your dissertation.

Twists and turns of a crappy idea

  • Worst case scenario: you delete it from your .tex file.
  • Problem: not much to do from here. Try to redo all your work.

  • Learn to use , even if in just a basic way.
  • keeps a history of your document within that document.
  • is free, with many open source tools to help.

How does it work?

  • Works only on plain text files.
  • Creates snapshots of your work, by comparing them to the previous state.
  • You can save a new snapshot ("commit") whenever you want.
  • Possible to go back to previous versions ("a previous commit") of your work.

Advantages

  • Flexible version history of your work.
  • It's smart: multiple users can work on the same file.
  • Combined with git hosting services, you can store your work online.
  • It's free!

Learn by doing

  • Check if git is on your system.
  • Open a terminal window, and type:

        git --version
    
  • If you get something like, the following, you're good.

If not, then install

Learn by doing

Using Gitkraken: Benefits

  • Open Source
  • Works cross-platform
  • Intuitive
  • Looks pretty

How to git: brief

  1. Initialise a git repository (only once)
  2. Work on the file within
  3. Stage the file
  4. Write a commit message
  5. Commit the changes
  • After 5. you have a recorded 'snapshot' of the file, which you can revisit later.

How to git: Initialise

  • In Gitkraken:
    • File > Init Repo
    • or: ctrl+I/cmd+I

How to git: Work

  • Outside of Gitkraken
  • Use LaTeX in the normal way

How to git: Stage

  • Inside of gitkraken
  • Click 'stage files'

How to git: Write

  • Inside of Gitkraken: write a note specifying what this snapshot represents
  • Be concise, but clear.
  • Why is this snapshot useful?
  • What happened?
  • Effectively: if you ever need to revisit this snapshot: why is it a good one to go back to?

How to git: Write

How to git: Commit

  • Finally, hit 'commit' to commit the changes to the snapshot.

Git: Further Benefits

  • Sync to online repos: either Github or Gitlab.
  • This is like a better version of dropbox.
  • But, it is not automatic, so you must commit your changes and push them to the remote.

Syncing the repo to Github

  1. Connect Gitkraken to your Github account.
    • Preferences > Authentication > Github > Connect to Github
  2. Click 'continue authorization'.
  3. Add in your login credentials.
  4. You're good.

Create a Github repo

Fill out info

  • Tip: Initialise with a TeX .gitignore file.

Clone the repo

  1. File > Clone Repo
  2. Select 'Github.com'
  3. Specify location
  4. Select repo to clone
  5. Clone the repo!

Work, commit + push

  • Go through the normal workflow.
  • When ready to sync, click 'Push'

Useful links: