Lesson GIT

Introduction to Git

This lesson is still in 'draft' status, meaning that it's not ready for usage yet.

Individual Post-Class Exercises
  1. Start-of-lecture Slides (Required)
    Online students will need to read these on their own. 
    Hybrid students will see them at the start of class.

  2. Useful links:

    1. http://git-scm.com/book/en/v2
      Nice, although it tends to dive into the details immediately.

    2. https://www.gitignore.io/ - to generate .gitignore files

  3. Download and install git

    1. Let's use Atlassian Source Tree

    2. We're going to use use git-extensions, which works well on Windows (and apparently can run under Mac/Linux using Mono).
      It looks like the project is currently hosted on GitHub, even thought the top link goes to SourceForge.  It appears that SourceForge has the same installer package as the GitHub site (at least as of 1/29/2016).
      Download for Windows: http://sourceforge.net/projects/gitextensions/
      Project Home page: https://github.com/gitextensions/gitextensions (at the bottom there's a link for Mac/Linux users)

    3. Note that while git-extensions includes a Visual Studio plugin we're going to be using the command prompt for everything.  Why?

      1. Almost all the online help for git uses the command prompt.
        If you get stuck there won't be any advice for the plugins or GUI (typically) but there will be advice on using the command prompt.

      2. git is robust, solid, and reliable, but still immature in the sense that people are still figuring out how best to use it.  Plus, it's open-source, which tends to produce more options for a given task anyways.  There are _lots_ of specialized options out there, each one of which has a small audience of users.
        The prompt is the 'common denominator' for all git users, so that's how people typically use it (and post help on it)

      3. If you want to work in computers then you need to know how to use a command prompt.  We won't be using it much, but it will be enough to get you a good introduction to this

  4. Introduction to the bash shell
    Important points:

    1. Nowadays people use the command-line interface for issuing commands to the computer and for scripting (because it has a built-in programming language). 
      It *used* to be that people would use the command-line shell for all their interactions with the computer - everything from moving files around to starting programs.  Nowadays GUIs are much easier to use for these sorts of things so we don't use the CLI shell anymore
      It's worth noting that this used to provide a nice, smooth path from just using the shell for routine things, to learning a little bit (a loop, say) in order to automate something small, to learning more about shell scripting, etc, etc.
      Take-away: while you need to know how to use the shell well enough to issue commands to git you should plan on continuing to use your GUI as much as possible

      1. Note that this means that if you search the web for help with "bash shell" you'll probably find more references on shell programming than you will on actually using the shell.

    2. Start the git bash to get a command prompt

      1. Note that people sometimes refer to the program as the 'shell', or the 'bash shell', or just 'bash'.

    3. Walk through the tutorial at http://swcarpentry.github.io/shell-novice/ (note that it's not enough to double-click on the .ZIP to extract it - you need to right-click on it and the select "Extract All...", just like

      1. Read the above page for an overview of why people still use the shell

      2. Read the first bash shell tutorial to understand the 'story' used in the tutorials

      3. As you read the second bash tutorial make sure that you follow along on your computer, step by step.

      4. You should read the third shell tutorial and follow along with the steps that it outlines.
        These sorts of commands you should normally do with your GUI instead of the CLI, though.  I want you to read this stuff even though you won't use it because the git tutorials will use these commands and so you should be familiar with what they are.

  5. Getting started with git - overview
    We're going to first do an online tutorial and then do a practice run with an online simulator

    1. The the overview / motivation at http://swcarpentry.github.io/git-novice/  and the first git tutorial to understand what version control is used for

    2. At this point you should switch gears and go for a 'guided tour' of how git is used, using the interactive, online tutorial: https://try.github.io/levels/1/challenges/1.

      1. The basic idea is that you can type the command into the 'prompt' and then hit enter and it'll show you the result. 
        Alternately you can push the button to have it type the command in for you (but you still have to hit enter to actually make the command happen).

      2. Each step also has a brief explanation about what the step does.  At the bottom-left of the page is a 'file browser', and the bottom-right has some interesting tips.

      3. Expect to spend a minute or so per step, so about half an hour on the entire thing. 
        The goal here is to get an idea of how git works but NOT to become an expert in everything all at once.
        Steps 1.1 through 1.9 cover the basic process of adding stuff to the repo
        Steps 1.10 - 1.12 are about remotes (remote/online servers) - you will need to know this
        Steps 1.13 - 1.17 are about comparing files (between your working copy, the files you've committed to your repository, and the files that have been temporarily stored in your staging area). 
        Steps 1.18 -1.25 are about branches - easy branching is one of the nicest features of git, but one that we won't be using much.  Zip through this part to see a nice explanation/demo, but don't worry about learning/retaining any of it for this class :)

        In the next part we'll go back to the tutorial to do actual work on your computer

  6. Getting started with git - working with a local repo
    Essentially what we're going to do is practice committing stuff to our local repo.  If this is all you did then you'd basically be making local backups of your work.
    1. The 'Setting Up Git' tutorial will tell you how to enter your email address, set up a default editor, and generally edit & check your config settings.
      Note that Notepad++ is not built into Windows - you need to download that separately.  I think that you can also just skip the editor step - it'll use the normal Notepad by default, but it only does this if you leave out the commit message when committing (so if you type the message in on the command line you won't need to use the editor)

      1. Maybe point out http://git-scm.com/book/en/v2/Getting-Started-Getting-Help somewhere along the line

    2. The Creating a Repository tutorial will walk you through creating a new repo from scratch. 

    3. The Tracking Changes tutorial is probably the most important tutorial in this collection.  It shows you how to make changes to your files, and the save that work into your repo.

      1. Note that the author likes to use the nano editor.  Whenever the tutorial lists something like "nano mars.txt" just imagine that they've opened up the mars.txt file inside Visual Studio and then they make whatever changes they describe.

      2. Maybe point them at this picture/section: http://git-scm.com/book/en/v2/Getting-Started-Git-Basics#The-Three-States 

    4. The Exploring History tutorial will show you a bit about how to interact with the files stored in your local repo

    5. You can mostly skip the Ignoring Things tutorial.  It's interesting stuff, but please be careful not to accidentally exclude stuff that you need to hand in.
      If you're curious, the instructor uses this feature in the starter projects to stop you from uploading your bin & obj directories



      This seems like a good place to end the first lesson - an exercise to create me a repo, put something into it, and then email me the output of git log, maybe

  7. Getting started with git - working with a online repo
    Essentially the workflow is 

    1. The Remotes In Git tutorial will demonstrate how to upload your work to something like GitHub.  Read through this BUT DO NOT DO THIS
      SKIP THIS?

      DO NOT UPLOAD YOUR HOMEWORK TO GITHUB
      If you do you're sharing your homework on the Internet, which violates the plagiarism policy for this class.

      (Include plea to not share stuff here?  Point out that this is all foundational skill-buliding, you need to do this for yourself in order to learn it, and I can't create 50 individual variations on each exercise each time I teach this course?)

    2. Instead of showing the above, what about something GitLab-specific?

    3. Exercise: Clone/fork a repo on GitLab, make sure it's private, edit it online, and then get it ready to be graded

    4. Exercise: Pull private fork to local machine, make a change, push it back to the server, prep it for grading

  8.  

 
In-Class Materials:

In-Class Videos (These were recorded during this class, and are made available here in case you want to refer to them later)

Instructor's Materials:
Notes

Word doc with screenshots

Managing multiple BitBucket accounts on one computer:

http://stackoverflow.com/questions/8186441/multiple-bitbucket-accounts 

Forking vs. cloning:

Maybe forking keeps some extra refs around?

To test: check out the fork under e:\work\student_work\temp\firefox_test_2
Repeat the setup (use firefox to create a new repo, add some junk files, then CLONE the repo into Chrome, then git clone it onto my computer, then examine what's different

Git

  1. http://www.milezero.org/index.php/tech/education/teaching_with_git.html
    1. Use command line (Pro Git will be usable)
    2. Don't make my own tutorials
    3. Pro Git, most online help is command-line based
    4. Explain the concepts behind each action
      'black box' stuff doesn't really work
    5. Set up origin repo for students to clone

 

  1. overview (with questions?)
  2. follow https://try.github.io/ to get a feel for how things work
    1. Mention the file-browser (since it might be off-screen for a small window)
    2. It's also worth browsing the 'advice' box (lower-right)
    3. Students can just click on the button to add the text
      This is good to do the first time (it might be worth redoing these by hand just to get the feel for a command line prompt)
      They'll still need to hit the enter key to make the command work
    4. This does a nice job with the early stuff, but then also illustrates merging as well
    5. Emphasize that we'll be following a different workflow (clone, add/modify, then re-upload to the original)
    6. At the end there's a link to http://gitreal.codeschool.com/levels/1
      If students have the time they could dive into this, but emphasize that this isn't going to be used right now
  3. Have students sign up for BitBucket.org
  4. Have them do a simple create repo-change it-push it back to server exercise
    Point them to the tutorial
    https://confluence.atlassian.com/bitbucket/git-tutorial-keep-track-of-your-space-station-locations-759857287.html