1 of 27

Using GitHub

for Project Collaboration

2 of 27

Reminder: What is GitHub?

  • Git is a language.
    • We use it for version control.
  • GitHub is a company!
  • GitHub, the company, offers a platform to store and share your code “in the cloud” (ie: online).
  • GitHub is commonly used for collaborating on projects.

3 of 27

How to Collaborate on Projects Hosted on GitHub

  1. Create a Repository.
  2. Create a Branch.
  3. Make and commit changes.
  4. Open a Pull Request.
  5. Merge a Pull Request.

This lesson demonstrates how to use the GitHub interface for collaborating on small projects. You’ll usually use the command line (Terminal) for collaborating on large projects.

4 of 27

The Journey Ahead

5 of 27

Step 1: Create A GitHub Repository

  • A repository holds a single project.
  • Repositories can contain
    • folders.
    • files.
    • Images & videos.
    • a README.
    • data sets.
    • anything your project needs.

6 of 27

Step 1: Create A GitHub Repository

(a.k.a. “repo”)

  1. In the upper right corner, next to your avatar, click on the “ + ” and then click on New repository.
  2. Name your repo hello-world.
  3. Give it this description: “Trying out collaboration”.
  4. Select Initialize this repository with a README.
  5. Click the green “Create repository” button.
  6. You’ll be taken to the webpage for your new repo.

7 of 27

8 of 27

main

9 of 27

Step 2: Create A Branch

  • Branching is a way to work on different versions of a project at one time.
  • By default, your repository has one branch named “main”.
  • When you create a branch of the “main” branch, you’re making a copy of the “main” branch as it exists at that point in time.

10 of 27

Step 2: Create a Branch (continued)

  1. Navigate to your new repository hello-world.
    1. This is the page GitHub sends you to directly after you click on the green “Create new repo” button.
  2. On the left side towards the middle of the page, click on the button that says branch: main.
  3. Create a new branch by typing readme-edits into the textbox that appears.
  4. Click on the blue Create branch box.

11 of 27

12 of 27

Step 3: Make and commit changes

  1. Click the README.md file.
  2. On the right side, towards the middle of the page, click the pencil icon to edit the README.md file.
  3. In the editor, write a bit about yourself.
  4. Scroll down until you see the comment box called Commit changes. Write a title and a commit message that each describe your changes.
  5. Select the radio button for “Commit directly to the readme-edits branch”.
  6. Click the green Commit changes button.
  7. You’ll be taken back to the webpage for your repo.

Note: In both Git and GitHub, saved changes are called commits

13 of 27

14 of 27

Step 4: Open A Pull Request

When you open a pull request, you’re proposing that one of the project’s organizers:

  1. Review your changes.
  2. Agree to pull your changes into the main branch.

Pull requests show the differences in content between the 2 branches.

15 of 27

Step 4a: Open A Pull Request

Click the Pull Request tab. This takes you to the Pull Request page. Click the green New pull request button.

16 of 27

Step 4b: Open A Pull Request

Select the branch you made, readme-edits, to compare with main (the original).

17 of 27

Step 4c: Open A Pull Request

Look over your changes in the diffs on the Compare page, make sure they’re what you want to submit.

18 of 27

Step 4d: Open A Pull Request

When you’re satisfied that these are the changes you want to submit, click the big green Create Pull Request button.

main__

19 of 27

Step 4e: Open A Pull Request

Give your pull request a title and write a brief description of your changes.

main

20 of 27

Step 4f: Open A Pull Request

Press the green Create pull request button.

21 of 27

Step 5a: Merge Your Pull Request

Click the green Merge pull request button to merge the changes into master.

Click the green Confirm merge button.

22 of 27

Step 5b: Merge Your Pull Request

Delete the readme-edits branch since its changes have been incorporated, with the Delete branch button in the purple box.

23 of 27

What We Just Did

24 of 27

What if there’s a merge conflict?

If your two branches have changes that are not compatible, we have a merge conflict. GitHub prevents you from merging until the conflict has been resolved by choosing which version you want to keep.

25 of 27

Git Remote

git remote add <name> <url>

The commands presented above let you manage connections with other repositories.

26 of 27

In terms of use-cases, I imagine you would use the 'git pull origin main' form when you want to merge your current branch with a different branch than the one you created your local one with originally. If you just want to merge the latest changes on the remote copy of your current branch (the one you used to create your local copy of the branch), you would use the 'git pull' form.

Git Pull and Git Pull Origin Main

27 of 27

More GitHub Resources

GitHub Hello World has details of Hello World exercise.

GitHub Guides has all the info to get you started.