GitHub in 10 easy steps

Tags how-to

Objective

Learn how to use GitHub for your platform.

Environment

  • Mac
  • Windows
  • Linux

Procedure

GitHub for Individuals in 10 Easy Steps:

  1. WHAT IS IT:  Git is a tool to track and document changes in your work.  This work could be anything.  Documents, coding, data, the type doesn’t matter. You can do this as an individual or in a group.

  2. WHY USE IT:  Easily keep track and back out changes in your work.  Much like google drive has history on document edits, you can use git for that but with notes about why you made the changes.  It documents what you were thinking when you made the edit.  If you add a bit to a piece of code as trial and error, you can simply back out to the last working code.  If you have data that you will work on over the course of your career but need to give specific versions of the data out based on maybe journal or book publication, you can branch the data to show the next phase of your work.

  3. TRY IT: https://try.github.io/levels/1/challenges/1 

  4. SIGN UP: GitHub has two types of accounts: personal user accounts and organization accounts. To get started, you  will need to create a personal account, if you don't have one already. Each individual user on GitHub should have exactly one personal account. There's no need to maintain a separate account just for teaching, we'll use an organization for that. It's totally free to create an account, so go ahead and sign up.  The question you do have to decide is whether you need a private repository or not.  Private repositories may be useful when you are working on intellectual property or data that may not be disclosed either immediately or until after publication of your results.

  5. INSTALL GIT: GitHub provides desktop clients that include a graphical user interface for the most common repository actions and automatically updating command line edition of Git for advanced scenarios.  

  6. LEARN SOME VOCABULARY: https://help.github.com/articles/github-glossary 

    1. Users are personal GitHub accounts. Each user has a personal profile, and can own multiple repositories, public or private. They can create or be invited to join organizations or collaborate on another user's repository.

    2. A repository is the most basic element of GitHub. They're easiest to imagine as a project's folder. A repository contains all of the project files (including documentation), and stores each file's revision history. Repositories can have multiple collaborators and can be either public or private.

    3. SSH keys are a way to identify yourself to an online server, using an encrypted message. It's as if your computer has its own unique password to another service. GitHub uses SSH keys to securely transfer information from GitHub.com to your computer

    4. A commit, or "revision", is an individual change to a file (or set of files). It's like when you save a file, except with Git, every time you save it creates a unique ID (a.k.a. the "SHA" or "hash") that allows you to keep record of what changes were made when and by who. Commits usually contain a commit message which is a brief description of what changes were made.

    5. A diff is the difference in changes between two commits, or saved changes. The diff will visually describe what was added or removed from a file since its last commit.

    6. Fetching refers to getting the latest changes from an online repository (like GitHub.com) without merging them in. Once these changes are fetched you can compare them to your local branches (the code residing on your local machine).

    7. Pull refers to when you are fetching in changes and merging them. For instance, if someone has edited the remote file you're both working on, you'll want to pull in those changes to your local copy so that it's up to date.

    8. Pushing refers to sending your committed changes to a remote repository such as GitHub.com. For instance, if you change something locally, you'd want to then push those changes so that others may access them.

  7. CREATE A REPOSITORY: 

    1. Command based - No data yet:  

      1. mkdir project

      2. cd project

      3. git init

    2. Command based - If you have existing data:

      1. cd project

      2. git init

      3. git add .     

        • include everything below ./ in the first commit:

      4. git commit

    3. Graphical:  Simply open the Git icon git-gui.jpgthen drag the folder into the application or select it after opening the + down box.

      • Mac             git-macgui.jpg

      • Windows                 git-wingui.jpg

  8. MAKE CHANGES & COMMIT:

    1. Command based:

      1. git add [file]

      2. git commit - m “message”

      3. git push origin/master

    2. Graphical:

      1. Drag the file to the folder of your repository or create it in that folder.

      2. Enter a summary and description in the git window

        • Mac                             git-mac-commit.jpg

        • Windows                    git-win-commit.jpg

      3. Click on Commit & Sync (mac) or Commit to master (win)button

  9. REVIEW HISTORY:

    1. Command based:

      1. git log 

      2. git log --follow [file]

      3. git diff [first branch]...[second branch]

      4. git show [commit]

    2. Graphical:

      1. Click on the history tab to see your commits.

        1. Mac                  git-mac-log.jpg

        2. Windows     git-win-log.jpg

  10. BACKOUT CHANGES:

    1. Command based:

      1. git reset [commit]

      2. git revert [commit]

    2. Graphical:

      1. Go to history and click on the commit you would like to revert to or roll back to then 

      2. Click on the appropriate option.

        • Mac  git-mac-revert.jpg

        • Win   git-win-revert.jpg

Additional notes

This document was created for use in HPC 470 and for use by researchers in managing their research related work.

Work with other people’s code by cloning: https://help.github.com/articles/fork-a-repo

For example: git clone https://github.com/umich-flux/hpc470.git  will create a copy of the HPC 470 

course code in the directory where you enter this command:

git.jpg

Or by web by clicking on the download zip or clone in Desktop button in the lower right of the web page:

gitweb.jpg

Cheat Sheet: https://opensource.com/downloads/cheat-sheet-git

Keep your data here too: https://github.com/datasets 

Websites:: https://opensource.com/article/19/4/building-hosting-website-git

GitHub for Teaching: https://education.github.com/teachers 

Full User Manual:  https://www.kernel.org/pub/software/scm/git/docs/user-manual.html 

A practical Learning Exercise: https://opensource.com/article/19/5/practical-learning-exercise-git

1-Hour webinar: http://www.youtube.com/watch?v=U8GBXvdmHT4 

Details

Article ID: 1740
Created
Wed 5/27/20 10:39 AM
Modified
Thu 10/8/20 4:10 PM