Skip to content

Using Git

Tessa Rhinehart edited this page Jan 23, 2024 · 41 revisions

Table of contents

Learn the basics

Follow Justin's lesson on Git if you are a first-time user, or need a refresher on how to use Git.

Initial setup

Make a GitHub account and make sure you have Git installed on your computer

Make a folder for repositories in your home folder on whatever place you're setting up Git--for instance, you'll probably want to set up some repositories on phoebe.

Create a folder to keep your git repositories organized, e.g. one called ~/Repositories or ~/Code.

Set up an SSH key if you want:

  • On github.com, go to your Settings > SSH and GPG keys
  • Copy your public key from ~/.ssh/id_rsa.pub (create key with ssh-keygen)
  • Find the SSH url of your repository by clicking on the "clone" button in the repo and "Use SSH" in the upper right corner of the dialogue box
  • Change the url of your origin to the SSH url using git remote set-url origin <new_url>

back to top

Developing with branches

If you're working on an ongoing bug fix or new feature implementation, use a separate, descriptively named branch. This helps to:

  • Keep track of all the changes happening in one project
  • Allow for testing of the feature/fix while keeping a standard version of the code around

In general, the workflow is as follows:

  • Make a branch for your feature off of the develop branch
  • Build the feature, committing to the feature branch as it is built
  • Then, submit a pull request (PR) to the develop branch
  • Once the PR is merged/accepted, delete your feature branch

Helpful commands

Check the available branches and see which one you're on:

$ git branch

Create or switch to a branch:

# Create and switch to branch
$ git checkout -b <new_branch_name>

# OR: switch to a branch that's already created
$ git checkout <branch_name>

Add all changes - helpful if many files have been deleted

git add -u

Workflow

  1. Create a feature branch off the develop branch:
git checkout -b <feature_branch_name> develop
  1. Start making changes that are relevant to the branch

  2. Commit your changes with a descriptive message.

$ git add <files_you_modified>
$ git commit -m "<descriptive_message>"
  1. Push your changes to a (new) branch on the remote:
$ git push -u origin <your_branch_name>
  1. Go to github.com, create a pull request to the develop branch (not master!)

  2. Make any more necessary changes to the pull request

  3. Once the feature is complete, merge the PR and delete the branch on github.com

  4. Switch out of your local feature branch into develop, delete the local feature branch, and pull your merged changes:

$ git checkout develop
$ git branch -d <your_branch_name>
$ git pull