Dr. Pamela Wisniewski, Director of the STIR Lab and iUX Academy

GitHub Setup and Usage

GitHub Setup and Usage

Git vs. GitHub

If you are new to Git, you might be confused about the difference between Git and GitHub, so hopefully this will help to clarify.

  • Git is a version control system that runs on your computer, without the need for an internet connection. There are a number of commands that you can execute to manage different versions of the code you are writing within a Git repository (see Basic Git Commands below)
  • GitHub is one of many services that host these Git repositories (repos) on the internet. There are others, such as BitBucket and GitLab. These services make it easy for teams to work together, as there is a central, remote location that all of the code lives. Git commands like push and pull help keep the remote repo and your local repo in sync. When you push your code to GitHub, your teammates can pull that code to their local repos, and vice versa.

Creating a GitHub Account

  1. Go to github.com
  2. Enter a username, email, and password to sign up
    • If you need to be added to a repository, you will need to send this username to whoever is managing it

Installing and Setting Up Git

  1. To install Git, if you are running Windows, click here to start the download. Otherwise, follow the instructions on the official website to install:
  2. Once Git is installed, open your command line
    • On Windows, this is the Command Prompt
    • On Mac or Linux, this is the Terminal
  3. Configure Git with your identity:
    $ git config --global user.name "Your Name"
    $ git config --global user.email github_account_email@example.com

Creating and Cloning a Repository

To create a new repository:

  1. Log into GitHub (see Creating a GitHub Account)
  2. Click “New” next to “Repositories” in the left sidebar, or click the + (plus) icon in the top right and click “New repository”
  3. Select “STIR-Lab” as the Owner
    • If you don’t see “STIR-Lab”, you’ll need to send whoever manages the STIR Lab GitHub your username and ask them to add you to the organization. Once added, accept the invite that you should receive via email.
  4. Choose a short, memorable name that is all lowercase with dashes between words (e.g., “my-cool-repo”)
  5. Write a brief description for the project that will help future students understand (e.g., “Mobile app for the Cool Research project”)
  6. Select “Private”
  7. Select “Add a README file”
  8. Select “Add .gitignore” and choose a template that is relevant to the current project (otherwise leave it as None)
  9. Click “Create repository”

To clone the new repository to your local machine:

  1. In the GitHub repo, click the green “Code” button
  2. Copy the link to the remote repo
  3. Open your command line
  4. cd to where you want to store the repository
  5. Run $ git clone <copied link>
    • For example, $ git clone https://github.com/STIR-Lab/my-cool-repo.git

Creating and Switching Branches

A branch represents an independent line of development. A branch can be created when you want to make changes in a new working directory (e.g. when fixing an issue that you do not want to change in the master branch). To create a new branch and switch to it, use the following commands:

  1. $ git branch <branchname>
  2. $ git checkout <branchname>

To create a branch, and switch to it at the same time:

  1. $ git checkout -b branchname

Committing Code

The “commit” command is used to save your changes to the local repository.You need to indicate which file and changes need to be saved before running the Git commit command. To commit a file:

  1. git add <filename>
  2. git commit -m "<message>"

The message should include a brief description of your changes e.g. “Changed styling on homepage”.

Staying in Sync (Pulling/Pushing)

The git push command is used to transfer or push the commit, which is made on a local branch in your computer to a remote repository like GitHub. You can push to Github using the following command:

  1. git push 'remote_name' 'branch_name'

If you make a change in a repository, git pull  can allow others to view the changes and access the most updated versions of the repository. You can make a pull request using the following command:

  1. git pull 'remote_name' 'branch_name'.

Creating Pull Requests

Create a pull request whenever you want to merge your changes up into a higher branch that you do not directly manage (e.g., merging a new feature from your branch into development, merging )

  1. Log into GitHub (see Creating a GitHub Account)
  2. Navigate to your repository
  3. Click “Pull requests” near the top
  4. Click “New pull request”
  5. Select your repository for “compare:” and the repository you want to merge into for “base:”
  6. Review the changes as necessary and click “Create pull request”

Adding Members to a Repository

If you have the necessary permissions to add members to a repo, do so as follows:

  1. Log into GitHub (see Creating a GitHub Account)
  2. Navigate to your repository
  3. Click “Settings” near the top
  4. Click “Manage access” in the sidebar
  5. Click “Invite teams or people”
  6. Enter the username of the GitHub user you wish to add
  7. Select an appropriate role and click “Add <username> to this repository”