Skip to main content

Lesson 2 of 4 15 min read

GitHub repositories and collaboration

Publish a repository to GitHub, keep it in sync with push and pull, and collaborate through pull requests and code review.

In this lesson you will

  • Connect a local repository to a GitHub remote and push and pull changes
  • Clone a repository and contribute through branches and pull requests
  • Explain good collaboration practices such as code review and issues

Git and GitHub are different

Git is the version control tool on your computer. GitHub is a hosting service for Git repositories with collaboration features on top: pull requests, code review, issues, project boards and automation. GitLab and Bitbucket are similar services.

Publishing your repository

  1. Create a free account on github.com and click New repository. Leave it empty (no README) if you already have local commits.
  2. Connect your local repository to it and upload your commits:
Terminal
git remote add origin https://github.com/your-username/portfolio.git
git push -u origin main

origin is the conventional name for the main remote. -u remembers the connection, so next time git push is enough. GitHub asks you to authenticate; use the browser sign-in or a personal access token, not your account password.

Staying in sync

  1. Local repository
  2. git push
  3. GitHub
  4. git pull
  5. Teammate's repository
5-step diagram
  • git push uploads your new commits.
  • git pull downloads new commits from the remote and merges them into your current branch.
  • git clone https://github.com/org/project.git copies an existing repository, with its full history, to your computer.

Pull before you start work each day so you build on the latest code.

The pull request workflow

Most teams never commit directly to main. Instead they use feature branches and pull requests (PRs):

  1. git switch -c fix-contact-link and make your change.
  2. Commit and push the branch: git push -u origin fix-contact-link.
  3. On GitHub, open a pull request from your branch into main. Describe what you changed and why.
  4. Teammates review the code, leave comments and request changes. Automated checks (covered later in this path) run the tests.
  5. Push more commits to the same branch to address feedback; the PR updates automatically.
  6. When it's approved and the checks pass, merge the PR. Delete the branch.

Code review catches bugs early, spreads knowledge across the team and keeps the code consistent.

A pull request from first push to merge

You sends to GitHub: push the branch fix-contact-link. You sends to GitHub: open a pull request into main. GitHub sends to Teammate: review requested, checks run. Teammate replies to You: comments, then approval. You sends to GitHub: merge into main

Contributing to projects you don't own

For open-source projects, you usually can't push branches directly. Instead you fork the repository (make your own copy on GitHub), push your branch to the fork and open a pull request back to the original project.

Issues and README files

Issues track bugs, feature requests and tasks, and a PR can close an issue automatically when its description says "Fixes #12". A good README.md explains what the project does, how to install and run it, and how to contribute. It's the first thing visitors and recruiters see.

Hands-on exercise

Push the repository from the previous lesson to a new GitHub repository. Then practise the pull request workflow on your own project: create a branch, improve the README with a "How to run" section, push the branch, open a pull request, review your own diff on GitHub and merge it. Finally, run git pull on main locally and confirm the change arrived.

Knowledge check

3 questions • 70% to pass • Practice only, no certificate

  1. 1.Which command downloads a full copy of an existing GitHub repository?
  2. 2.Your teammate merged changes into main on GitHub. How do you get them locally?
  3. 3.Why do teams use pull requests instead of committing directly to main?
0 of 3 answered

Key concepts

  • Git runs locally; GitHub hosts repositories and adds collaboration features.
  • git remote add, git push and git pull connect and synchronise local and remote repositories.
  • Teams change code through feature branches and reviewed pull requests rather than committing to main.
  • Forks let you contribute to projects you can't push to; issues and READMEs organise and explain the work.