TUTORIAL: Tell Me How To Git - radiatoryang/fall2018_gamedev1_morning GitHub Wiki

0. have a Unity project

  • it's OK if it's a brand new Unity project
  • make sure you know the folder's location on your hard drive

1. download and install Sublime Merge

  • go to https://www.sublimemerge.com/ and download and install it for free
  • DO NOT google it and go to "Sublimerge"... it's called SUBLIME MERGE. Two words.
  • You may have used SourceTree or GitKraken in the past. GitKraken has locked an important function behind a paywall, and SourceTree is... well, let's just try something new.

2. create a Git folder ("repository") for your Unity project folder

A Git repository ("repo") is a folder that remembers how it changes

  • in Sublime Merge, click New Repository and browse to your project folder (the folder that has \Assets\ and \ProjectSettings\ in it)
  • (VERY IMPORTANT) then go to Tools > Edit .gitignore... and open it in a text editor like Notepad (Windows) or TextEdit (Mac)
    • google "gitignore unity", click the first result, then copy and paste that template into your own
    • WHY? the GitIgnore tells Git what files to ignore, and for Unity, we want to ignore 99% of these files... if you don't do this step, then you will have to check thousands of useless files every time you use Git

double-check: if Sublime Merge still says something like "Untracked files: 1000", then you did not do step 2 correctly

3. save a backup / snapshot (a "commit") in Git

Git is only useful if you make commits -- a commit is a snapshot / backup of all the files in your folder

  • click on Commit Message and type a good message to describe your changes
    • good example: "initial commit" or "added new script for level 3, changed rock model to look more orange"
    • bad example: "blah" or "robert smells" or "I hate git"
  • to commit a file, you must "stage" it first
    • click Untracked files button
    • click the Stage button next to each file you want to stage (hint: all of them)
    • if it takes too long: click on the long "master" button at the top (to open the Command Palette), type "stage all", and press ENTER
  • click Commit __ files button

double-check: you should now see your new commit in the timeline in the left sidebar... if you don't, repeat step 3

4. create a "remote" repo on GitHub

So far, we have done this only on your own "local" computer. We need to create your repo's twin on GitHub, the "remote" repo

  • go to GitHub.com, log-in, click the + button in upper-right corner, and select New Repository
  • name your GitHub repository
    • ignore GitHub.com's bad name suggestion
    • type in a good descriptive name, like "gamedev_midterm", or whatever your game concept is
    • (optional) type in a description too
  • Click the green Create repository button! DO NOT CLICK OR EDIT ANYTHING ELSE
    • DO NOT "INITIALIZE THIS REPOSITORY WITH A README"
    • DO NOT ADD A GITIGNORE (we already did that in step 2)
    • DO NOT ADD A LICENSE (you can do that later if you want)
  • Now on your empty GitHub repo page, copy the URL underneath "Quick setup"...
    • it should start with "https"
    • it should end with ".git"

5. link your "remote" repo

We need to tell your "local" repo about the "remote" repo on GitHub

  • in Sublime Merge, click the Up arrow in the upper-right
    • type in "origin" and press enter
    • paste the URL from that GitHub page (from the end of step 4)... (it should start with "https" and end with ".git")... then press enter

6. push your files

To upload your files to GitHub, you need to "push" your commits

  • click the Up arrow in the upper-right to push all commits to GitHub
  • if it asks you to login with your password, then do that

double-check: you should now see "origin/master" in the left sidebar

triple-check: refresh your GitHub repo page... you should now see your files there!


CONGRATS!!!... WHAT NOW?

  • work on your game as usual
  • every now and then, you should commit and push to save your progress
  • you already setup everything, so now you just need to repeat step 3 and 6

3. save a backup / snapshot (a "commit") in Git

Git is only useful if you make commits -- a commit is a snapshot / backup of all the files in your folder

  • click on Commit Message and type a good message to describe your changes
    • good example: "initial commit" or "added new script for level 3, changed rock model to look more orange"
    • bad example: "blah" or "robert smells" or "I hate git"
  • to commit a file, you must "stage" it first
    • click Untracked files button
    • click the Stage button next to each file you want to stage (hint: all of them)
    • if it takes too long: click on the long "master" button at the top (to open the Command Palette), type "stage all", and press ENTER
  • click Commit __ files button

6. push your files

To upload your files to GitHub, you need to "push" your commits

  • click the Up arrow in the upper-right to push all commits to GitHub
  • if it asks you to login with your password, then do that
⚠️ **GitHub.com Fallback** ⚠️