Skip to content

Code Management Resources

Help for Getting Started with GitHub

What are Git and GitHub?

Software versioning systems have been around a long time. Start writing, building and maintaining libraries of code or assembling smaller pieces into a large integrated program (for example a simulation model), you will likely discover a need to track and maintain versions. The program "git" is an open source software version control system, similar to Subversion, CVS, Mercurial and others.

When you installed Python or Anaconda, you got the latest version. Over time changes are made to the Python base code, perhaps to handle a update in operating systems, or to add a new feature. Version control systems allow users to update, revise and share code changes in a systematic way. The git tool works for any programming language - really any plain text formatted file. I use it to track Python, C, Fortran and even web site changes in HTML. The git tool allows you to check in and document updates, compare line-by-line differences between versions, and check out older versions of the code all through a simple command line application. It has become the dominant version control system because it stores files more efficiently, and maintains file integrity better than the other available tools.

The "HUB" in GitHUB is the cloud / networking component of software versioning. GitHUB provides cloud storage for code repositories, and a shared development platform all built on the git code versioning tool. Code posted to GitHUB can be accessed from anywhere by those with permission, can be shared publicly or with a select team of "private developers. GitHUB also serves as a social connection for programmers, who can swap code, review others work and provide guidance on how to solve or deal with problems.

Getting a GitHub Account

Anyone can sign up for a free GitHUB account through github.com. This allows you to create and maintain "public" repositories, which any member of GitHUB can find and access. You can also subscribe to GitHUB "Enterprise" to gain access to private repositories and other features.

Purdue University maintains its own "instance" of GitHUB. This provides all of the features of GitHub.com, but is under the control of ITaP. As an employee or student at Purdue (anyone with a Purdue career account), you can request an account or be added to an exiting research group organization within Purdue's GitHub system. This will allow you access to the full features of GitHUB Enterprise without paying - but only for as long as you are associated with Purdue. Information on requesting access to Purdue's GitHUB, see ITaP's GitHub and Versioning Control page.

Getting the Git code versioning tool

Linux Systems

The git tool is installed by default on all of Purdue's Research Computing (RCAC) Linux cluster systems. If using other Linux systems, check for availability by typing "which git" at the command line. If it is not available, first check with the system administrator to have it added to the system package management system, otherwise, you can install a personal instance of the tool - see Linux installation at Getting Started - Installing Git.

Windows and Mac OS X Systems

The easiest way to install git on Windows and Mac OS X systems is through installing GitHUB Desktop. This is an application you can install, even if you do not have administrator privileges, and gives you access to git through a user interface.

The other way to install git is to make use of a package manager on Mac OS X (such as Macports) or install a Linux emulator on Windows (such as cygwin). Help with setting both of those us can be found at the Wiki page Setting up Computers Outside of Class.

How to work with GitHub Classroom assignments...

These instructions are designed to help you work with GitHub Classroom assignments for the first time.

To get a course assignment

  1. In Brightspace, follow the assignment link, or log into GitHub Classroom

  2. Accept the assignment and GitHub will create a new repository with the name -, where is your GitHub.com username.

  3. In the final setup page, you will get a link to the new repository, click on it to get into the assignment. Here will be any instructions for the assignment and any additional information provided by the instructor.

  4. In the terminal, change to the directory where you are going to save all of your class assignments. Note that the cloning process will make a new subdirectory for each new assignment, so there is no need to make directories for Lab1, Lab2, etc.

If using a Linux terminal...

  • Use the change directory (cd) command to change directories, for example "cd ABE65100/" changes into the subdirectory ABE65100.
  • Use the list (ls) directory to see the contents of the current directory.
  • Use the make directory (mkdir) command to make a new subdirectory, for example "mkdir ABE65100" makes the subdirectory ABE65100.

  • Clone the assignment GitHUB repository (e.g., "git clone https://github.com/Environmental-Informatics/-.git"). For more details, see Getting a Git Repository

    • You can find the repository address to right side of the repository page, by clicking on the button that says "Clone or download".
    • This should open a pulldown menu that says "Clone with HTTPS".
    • If the window is labeled "Clone with SSH", then click on the link to the right of that message that says "Use HTTPS".
    • Under the words "Use Git or checkout with SVN using the web URL." there is a box that will have the web address of this assignment (https://github.com/Environmental-Informatics/assignment-01.git). Select all and copy, or click on the copy address button to the right of the address.
    • Paste the address into the "Git clone" command, as shown and press Return/Enter to start the command.
    • This will create a new directory that has everything you see in the repository.
  • Change into the new directory that resulted from the clone command (e.g., "cd -").

  • Everything you do in this folder can now be tracked and stored with GitHUB, so work on all files required as part of the assignment in this folder.

To submit or update an assignment

  1. Use the command "git status" to see what has changed.
    • Red files are changes not tracked by the repository, green are staged for storage.
  2. Use "git add " to stage a specific file or set of files (will turn from red to green next time you check the status).
    • Use use "git add ." to stage all files in the current directory (and its sub directories).
  3. Staged files can be committed to the repository using the "git commit" command.
    • Using "git commit" by itself will open an editor window where you can add a description of the changes made. This will probably be emacs, so when done typing the description, then type [Ctrl+x Ctrl+s] or click on the disk icon to save the text, then close the window.
    • Using "git commit -m "" ", will let you type the message directly on the command line rather than waiting on the editor window to open.
  4. Finally use "git push" to push the code from your local system to the GitHUB repository. This will require that you provide your GitHUB username and password.
  5. Once the changes have been pushed, you can see those changes when you reload the GitHUB web site.
  6. You can clone the repository as many times to as many places as you want, by default it will always be the latest version. However, changes that have not been "staged" to the local repository, "committed" to the local repository, and "pushed" to the GitHUB repository, will not be reflected in a new clone.
  7. If you edit on multiple locations, you may also have to use "git pull" to pull changes from GitHUB into an older clone of the repository. Doe this BEFORE you start editing. If not, you will need to read up on merging a pull request.

On-Line Reference Materials and Tutorials

Note

Are there any useful GitHub Classroom tutorials or should I get rid of this section.

Git Basics

Standard Git Commands

  • git clone

    .git - this creates a clone of an online repository

  • git init - the makes the current directory (and all of its subdirectories) a new repository.

  • git status - checks the status of the current repository

  • git add or git add . - adds specified file or all files (".") to the commit list.

  • git commit or git commit -m "" - commit files staged using "git add" to the local repository, and either opens the editor or uses "" to document changes being committed.

  • git push - pushes local repository changes to GitHub.

  • git pull - pulls remote repository changes from GitHub to local repository.

  • git diff - highlight differences between the file in the current folder and the last commit in the repository.

Most Common Processes

You've made changes to the local code and want to add them to your GitHub repository:

  1. "git add " or "git add ." to stage files to the commit list. Add only the files you want to commit with the same change message.
  2. "git commit" or "git commit -m " to commit staged files to the local repository. Files are added with a change message defined in an editor or on the command line.
  3. "git push" to push changes from the local repository to GitHub. Once on GitHub they can be shared with anyone who has access to your GitHub repository.

You want to update your local code repository because changes have been made and posted to GitHub:

  1. "git pull" to pull changes from GitHub to your local repository.

More general tutorials...

Note

Need to add materials on GitHub Desktop