Forking

In many environments you can’t just push a feature branch to the official upstream. This is to ensure reliability, cohesion, and security of the official branch.

It is common and customary to fork the upstream to your personal namespace, work on it, and then create a pull request based on that. We explain how this looks in real life.

Create a Fork

There are several ways to create a fork, all of them easy enough:

Forking with GUI

The easiest way to create a fork is to hit the Fork icon in the Github/Gitlab GUI:

  • Go to the main page of the repo: https://github.com/acme/widgets

  • Hit the Fork button

  • Use your namespace (default) and the original name for the repo

  • Clone your fork to your local system:

    # Your namespace is *tweetie*
    git clone https://github.com/tweetie/widgets
    
  • Add the remote to your fork:

    git remote add upstream https://github.com/acme/widgets
    

Forking with GH

Use the Github gh command to create a fork and the upstream in one blow:

gh repo fork acme/widgets --remote --clone

Forking with Gitlab GLAB

Gitlab’s glab tool is similar:

glab repo fork acme/widgets --remote --clone

Pull Requests via Fork

Once changes are made to the fork, its time to create a PR. First get ready:

  • Make your changes

  • Push changes up to your forked branch in GitLand as usual

GUI

  • Push changes to a branch in your fork

  • Go to your fork on Github, switch to the branch to be the PR

  • Click Compare & pull request” => “Create pull request”

  • Make sure the base branch is the official one, and not yours

Using GH and GLAB

Using Gitubs gh command:

gh pr create

Using Gitlab Glab:

glab mr create

These tools will usually prompt you for metadata like:

  • title

  • body

  • base

  • head

  • repo

Normally you just accept the default values and submit.

References