NUS Hackers Wiki
NUS Hackers Wiki
  • NUS Hackers Wiki
  • Hackerschool
    • Virtual Machines and Linux
    • Beginners' Guide to the Terminal
      • Introduction to the Terminal
      • Modern Shell Tools
      • Shell Scripting
      • Real World Scripting
      • Resources
    • Self-Hosting: Three Easy Pieces
      • 1. Setting up your server
      • 2. Running Services
      • 3. Monitoring your server
    • Vim
    • Introduction to Zig
      • Language Basics
      • Error Handling
      • Memory Management
      • Working with C
      • Exploring comptime
    • CI/CD with Github Actions
      • Background
      • Basics of Github Actions
        • Target workflow
        • Running unit tests
        • Linting code
        • Deploying to Github Pages
      • Advanced use cases
        • Pollers
        • Github script
        • Executing third-party scripts
        • Reusable workflows
      • Cookbook
    • Lightning Git
      • Git Concepts
      • Getting Started with Git
      • Making your first commit
      • Branching
      • Merge Conflicts
      • Integrating remote repositories
      • Collaborative Workflows
      • Commit Manipulation and Reflog
      • Interactive rebasing
      • filter-repo
  • Orbital
    • JavaScript
      • Browser Developer Tools
      • Getting Started
      • Datatypes
      • Operators and Operations
      • Loops and Conditions
      • Functions
      • Strings
      • Arrays
      • HTML
        • Getting Started
        • Tag Attributes
        • HTML Forms
        • Browser Inspector
      • CSS
        • Selectors
        • Colors in CSS
        • Measurements in CSS
        • The Box Model
        • Adding Styles - Part 1
        • Adding Styles - Part 2
      • Working with the DOM
        • Querying the DOM - Selectors
        • Querying the DOM - Element Attributes
        • Querying the DOM - Element Styles
        • Events with JS and HTML
        • Exercise: Click Counter
        • Editing the DOM
        • Fetch Requests
        • Exercise: The NUSMods API
    • React
      • Setup
      • State
    • React Native
      • Setup
      • Intro to JSX
      • Basic Syntax
      • Handling UI
      • Props
      • State Management
    • Git
      • Setup
      • Command Glossary
      • Fundamental Concepts
        • Getting Started
        • Integrating Remote Repositories
        • Branching
        • Merge Conflicts
      • Collaborative Workflows
        • Fork and PR Workflow
        • Branch and PR Workflow
      • Advanced Concepts
        • Ignoring Files
        • Commit Message Conventions
        • Github Collaborators
        • CI/CD with Github Actions
        • Advanced Git Commands
      • FAQ
    • Telegram Bot
      • Creating a TeleBot
      • API Calls
      • Telebot Basics
      • Integrating API's
    • Relational Database
      • Database Overview
      • Database Design
      • Entity Relationship Diagram
      • SQL Basics & PostgreSQL
    • TypeScript
      • Types and Interfaces
      • Utility Types
      • Typing Component Props, Events, and Hooks
      • Why You Should Avoid Using any (and What to Do Instead)
      • TypeScript Tricks You’ll Use All the Time in React
Powered by GitBook
On this page
  • What is forking?
  • How does it works for collaboration?
  • Workflow in action
  • What happens if my friend makes changes to the original repository?
  • Making PRs from forked branches
Edit on GitHub
Export as PDF
  1. Orbital
  2. Git
  3. Collaborative Workflows

Fork and PR Workflow

PreviousCollaborative WorkflowsNextBranch and PR Workflow

Last updated 26 days ago

This is the standard and recommended collaborative workflow by Github.

What is forking?

Forking is the process of creating a at-the-time copy of a remote repository. So any branches and code from the original (called "upstream") repository.

You can create a fork of a repository by visiting the upstream repository link and selecting the "Fork" button:

How does it works for collaboration?

Say your friend is working on the latest cutting edge project and you want to contribute some changes but you are not entirely sure how the codebase works. You can create a fork of your friend's repository, clone it locally, and play around with the codebase.

All of these changes will not be made available to your friend's repository as you have not made it explicit that they should be reflected on their repository.

Workflow in action

Now that we have established what forking is about, let us now see this workflow in action.

Then, clone the fork to your local machine and navigate to the folder:

git clone git@github.com:<your Github username>/new-folder.git fork-folder/
cd fork-folder/

Then, make a change to the repository like adding a new file, deleting something from hello.txt, etc.

Once done, commit those changes and push them to your fork.

git add .
git commit -m "fork changes"
git push origin main

Then, navigate back to the original repository and create a pull request. This time, you should notice that the compare (target branch) dropdown should include your fork's main branch as well.

Voila! You have now completed the fork and PR workflow. However, there are some caveats!

What happens if my friend makes changes to the original repository?

In such scenarios, it is necessary to add a new remote (see Integrating Remote Repositories for more information about this) pointing to the upstream repository.

To do so, you can run the following line (change the repository link where applicable):

git remote add upstream https://github.com/woojiahao/new-folder.git

Note that the URL used is the one under "HTTPS" since you do not have SSH access to the demo repository.

Once this upstream remote has been created, we can fetch any changes made to the original repository using the git pull command as such:

git pull upstream main

This will automatically fetch and merge any changes from the original repository to your local repository. However, if you want to have some more control over the merging process, you can use the following:

git fetch upstream main
git merge upstream/main

The first command retrieves the latest changes (but does not apply them locally). The second command performs a standard merge action, merging the changes from the upstream repository with your current local branch.

Making PRs from forked branches

You can also create a remote branch on the fork and make a PR from that branch as the source branch instead. Just create a new branch locally for the fork and push it to your fork:

git checkout -b new-fork-branch
git push origin new-fork-branch

Forking allows potential contributors to work on changes without directly affecting the original repository

Forks are stored under your account, not your friend's account

You can only make a single fork of a repository

First, create a fork of the demo repository: .

Everything else is the same as described in .

✅
✅
✅
https://github.com/woojiahao/new-folder/tree/main
Creating a pull request