STAT1013: Github

GitHub is a code hosting platform for version control and collaboration. It allows developers to store, manage, track, and control changes to their code. It is used for software development projects and makes it easy for developers to collaborate on projects from anywhere in the world. It is also used to host websites, share code, and keep project information up-to-date.

Github: basic usage

Basic usage of GitHub involves creating a repository, cloning a repository, adding files, making commits, and push commits.

git

Solo project

For developers who work alone, GitHub can be used for the following:

  • Storing code and keeping track of changes
  • Backing up projects
  • Managing tasks
  • Sharing code with colleagues and other developers
  • GitHub allows you to collaborate with yourself if you use multiple workstations to develop
  • GitHub even offers free web hosting
  • Employers like GitHub profiles (including me). Being active on GitHub can get you a job!

Moreover, following items will not be demonstrated in the lecture, but also very important:

  • Creating branches for different parts of a project
  • Creating and managing pull requests
  • Finding and contributing to open source projects

Step 0: Sign in/up on GitHub, and install GitHub Desktop App

Step 1: Create a public repository on GitHub

  • Log in to your GitHub account and go to the GitHub home page.
  • Click on the “+” icon in the top right corner and select “New repository”.
  • Give your repository a name and a description.
  • Select “Public” from the drop-down menu for the repository visibility.
  • click “Create repository”.
  • Once your repository is created, you can start adding files to it.

Step 2: Pull the repository from GitHub on GitHub Desktop

  • Log in to your GitHub account and navigate to the repository you want to pull.
  • Click the “Clone or Download” button and select “Open in Desktop”.
  • Select a local folder to clone the repository into.
  • Click “Clone” to clone the repository.
  • Click the “Fetch” button to fetch the latest version of the repository

Step 3: Commit & Push the repository on GitHub Desktop

  • Make the desired changes to the files.
  • Click the checkmark icon to stage the changes.
  • Enter a commit message to describe the changes.
  • Click the “Commit to main” button to commit the changes.
  • Push the changes to the repository using the “Push origin” button.

Work with Jupyter notebook: GitHub meets Colab

Google Colab has convenient Git integration. This will enable you to edit notebooks in Colab and then commit and push changes back to the repository without ever leaving Colab in your browser.

In order to access Git repositories, you need to allow Colab to access the repositories. Then, follow the steps below.

  • Click the checkbox for including private repos.
  • An authorization window from GitHub will pop up. (Make sure you are not blocking pop-up windows.) You should authorize Colab to access the organization and your repositories.
  • Under where it says “Enter a GitHub URL or search by organization or user,” search for your team’s repository name, such as statmlben if you want to clone my repos. Underneath the search bar, you will have a pulldown menu of available notebooks. Select the one you want to work on.

  • After you have made changes to your notebook, you can commit and push them to the repository. To do so from within a Colab notebook, click FileSave a copy in GitHub. You will be prompted to add a commit message, and after you click OK, the notebook will be pushed to your repository.

Work with Markdown: GitHub meets HackMD

To use GitHub with HackMD, you will need to do the following steps:

  • Log in to your GitHub account and connect it to your HackMD account.
  • Select the repository that you want to sync with HackMD.
  • Make changes to the document on HackMD and they will be automatically synced to the GitHub repository.
  • To create a new document on HackMD from a GitHub repository, select the repository from which you want to create the document.
  • The document will then be created on HackMD with the content from the repository.

Github Pages

You can configure your repository settings to use GitHub Pages, and your site will be available online. Here is a step-by-step guide to creating your website with GitHub Pages:

  • In the upper-right corner of any page, use the drop-down menu, and select New repository.
  • Enter username.github.io as the repository name. Replace username with your GitHub username. For example, if your username is octocat, the repository name should be octocat.github.io.
  • Under your repository name, click Settings.
  • In the “Code and automation” section of the sidebar, click Pages.
  • Under “Build and deployment”, under “Source”, select Deploy from a branch.
  • Under “Build and deployment”, under “Branch”, use the None or Branch drop-down menu and select a publishing source.
  • Optionally, open the README.md file of your repository. The README.md file is where you will write the content for your site. You can edit the file or keep the default content for now.
  • Visit username.github.io to view your new website. Note: It can take up to 10 minutes for changes to your site to publish after you push the changes to GitHub.

You can also change the title and description:

By default, the title of your site is username.github.io. You can change the title by editing the _config.yml file in your repository. You can also add a description for your site.

  • Click the Code tab of your repository.
  • In the file list, click _config.yml to open the file.
  • Click edit the file.
  • The _config.yml file already contains a line that specifies the theme for your site. Add a new line with title: followed by the title you want. Add a new line with description: followed by the description you want. For example:
    theme: jekyll-theme-minimal
    title: Octocat's homepage
    description: Bookmark this to keep an eye on my project updates!
    

    When you are done editing the file, click Commit changes.

Crash Course: Git and GitHub for Beginners (Optional)