Forking Workflow | Atlassian Git Tutorial (2024)

How it works

As in the other Git workflows, the Forking Workflow begins with an official public repository stored on a server. But when a new developer wants to start working on the project, they do not directly clone the official repository.

Instead, they fork the official repository to create a copy of it on the server. This new copy serves as their personal public repository—no other developers are allowed to push to it, but they can pull changes from it (we’ll see why this is important in a moment). After they have created their server-side copy, the developer performs a git clone to get a copy of it onto their local machine. This serves as their private development environment, just like in the other workflows.

When they're ready to publish a local commit, they push the commit to their own public repository—not the official one. Then, they file a pull request with the main repository, which lets the project maintainer know that an update is ready to be integrated. The pull request also serves as a convenient discussion thread if there are issues with the contributed code. The following is a step-by-step example of this workflow.

1. A developer 'forks' an 'official' server-side repository. This creates their own server-side copy.

2. The new server-side copy is cloned to their local system.

3. A Git remote path for the 'official' repository is added to the local clone.

4. A new local feature branch is created.

5. The developer makes changes on the new branch.

6. New commits are created for the changes.

7. The branch gets pushed to the developer's own server-side copy.

8. The developer opens a pull request from the new branch to the 'official' repository.

9. The pull request gets approved for merge and is merged into the original server-side repository

To integrate the feature into the official codebase, the maintainer pulls the contributor’s changes into their local repository, checks to make sure it doesn’t break the project, merges it into their local mainbranch, then pushes the mainbranch to the official repository on the server. The contribution is now part of the project, and other developers should pull from the official repository to synchronize their local repositories.

It’s important to understand that the notion of an “official” repository in the Forking Workflow is merely a convention. In fact, the only thing that makes the official repository so official is that it’s the public repository of the project maintainer.

Forking vs cloning

It's important to note that "forked" repositories and "forking" are not special operations. Forked repositories are created using the standard git clone command. Forked repositories are generally "server-side clones" and usually managed and hosted by a 3rd party Git service like Bitbucket. There is no unique Git command to create forked repositories. A clone operation is essentially a copy of a repository and its history.

Branching in the forking workflow

All of these personal public repositories are really just a convenient way to share branches with other developers. Everybody should still be using branches to isolate individual features, just like in the Feature Branch Workflow and the Gitflow Workflow. The only difference is how those branches get shared. In the Forking Workflow, they are pulled into another developer’s local repository, while in the Feature Branch and Gitflow Workflows they are pushed to the official repository.

Fork a repository

Forking Workflow | Atlassian Git Tutorial (3)

All new developers to a Forking Workflow project need to fork the official repository. As previously stated, forking is just a standard git clone operation. It’s possible to do this by SSH’ing into the server and running git clone to copy it to another location on the server. Popular Git hosting services like Bitbucket, offer repo forking features that automate this step.

Clone your fork

All new developers to a Forking Workflow project need to fork the official repository. As previously stated, forking is just a standard git clone operation. It’s possible to do this by SSH’ing into the server and running git clone to copy it to another location on the server. Popular Git hosting services like Bitbucket, offer repo forking features that automate this step.

Assuming the use of Bitbucket to host these repositories, developers on a project should have their own Bitbucket account and they should clone their forked copy of the repository with:

gitclonehttps://[email protected]/user/repo.git

Adding a remote

Whereas other Git workflows use a single origin remote that points to the central repository, the Forking Workflow requires two remotes—one for the official repository, and one for the developer’s personal server-side repository. While you can call these remotes anything you want, a common convention is to use origin as the remote for your forked repository (this will be created automatically when you run git clone) and upstream for the official repository.

gitremoteaddupstreamhttps://bitbucket.org/maintainer/repo

You’ll need to create the upstream remote yourself using the above command. This will let you easily keep your local repository up-to-date as the official project progresses. Note that if your upstream repository has authentication enabled (i.e., it's not open source), you'll need to supply a username, like so:

gitremoteaddupstreamhttps://[email protected]/maintainer/repo.git

This requires users to supply a valid password before cloning or pulling from the official codebase.

Working in a branch: making & pushing changes

In the developer's local copy of the forked repository they can edit code, commit changes, and create branches just like in other Git workflows:

gitcheckout-bsome-feature#Editsomecodegitcommit-a-m"Addfirstdraftofsomefeature"

All of their changes will be entirely private until they push it to their public repository. And, if the official project has moved forward, they can access new commits with git pull:

gitpullupstreammain

Since developers should be working in a dedicated feature branch, this should generally result in a fast-forward merge.

Making a pull request

Forking Workflow | Atlassian Git Tutorial (4)

Once a developer is ready to share their new feature, they need to do two things. First, they have to make their contribution accessible to other developers by pushing it to their public repository. Their origin remote should already be set up, so all they should have to do is the following:

gitpushoriginfeature-branch

This diverges from the other workflows in that the origin remote points to the developer’s personal server-side repository, not the main codebase.

Second, they need to notify the project maintainer that they want to merge their feature into the official codebase. Bitbucket provides a “pull request” button that leads to a form asking you to specify which branch you want to merge into the official repository. Typically, you’ll want to integrate your feature branch into the upstream remote’s mainbranch.

Summary

To recap, the Forking Workflow is commonly used in public open-source projects. Forking is a git clone operation executed on a server copy of a projects repo. A Forking Workflow is often used in conjunction with a Git hosting service like Bitbucket. A high-level example of a Forking Workflow is:

1. You want to contribute to an open source library hosted at bitbucket.org/userA/open-project

2. Using Bitbucket you create a fork of the repo to bitbucket.org/YourName/open-project

3. On your local system you execute git clone on https://bitbucket.org/YourName/open-project to get a local copy ofthe repo

4. You create a new feature branch in your local repo

5. Work is done to complete the new feature and git commit is executed to savethe changes

6. You then push the new feature branch to your remote forked repo

7. Using Bitbucket you open up a pull request for the new branch against theoriginal repo at bitbucket.org/userA/open-project

The Forking Workflow helps a maintainer of a project open up the repository to contributions from any developer without having to manually manage authorization settings for each individual contributor. This gives the maintainer more of a "pull" style workflow. Most commonly used in open-source projects, the Forking Workflow can also be applied to private business workflows to give more authoritative control over what is merged into a release. This can be useful in teams that have Deploy Managers or strict release cycles.

Unsure what workflow is right for you? Check out our comprehensive Gitworkflow comparison page.

Share this article

Next Topic
Comparing workflows
Forking Workflow | Atlassian Git Tutorial (2024)

FAQs

What is forking workflow in git? ›

The Forking Workflow helps a maintainer of a project open up the repository to contributions from any developer without having to manually manage authorization settings for each individual contributor.

What is the difference between forking and mirroring in git? ›

Fork vs.

A mirrored repository is a read-only copy of another repository that syncs with the original, mirroring all changes. Unlike a fork, a mirror does not allow for independent development but serves as a real-time backup or public mirror of a private repository.

Is gitflow outdated? ›

The phrase “Gitflow is dead” is an exaggeration. Like all tools and practices, Gitflow has its place. For projects that have specific release management needs or those that haven't migrated to CI/CD, Gitflow can still be very relevant.

What is the point of forking a process? ›

The purpose of fork() is to create a new process, which becomes the child process of the caller. After a new child process is created, both processes will execute the next instruction following the fork() system call. Therefore, we have to distinguish the parent from the child.

What is the difference between cloning and forking? ›

A fork creates a completely independent copy of Git repository. In contrast to a fork, a Git clone creates a linked copy that will continue to synchronize with the target repository.

What is the difference between branching and forking? ›

Key differences between a fork and a branch

Scope of isolation: Branches are isolated within the same repository, allowing easier collaboration among team members who have access to the repository. Forks, on the other hand, create a completely separate copy of the repository, which is useful for outside contributors.

What is the purpose of fork in Git? ›

A fork in Git is simply a copy of an existing repository in which the new owner disconnects the codebase from previous committers. A fork often occurs when a developer becomes dissatisfied or disillusioned with the direction of a project and wants to detach their work from that of the original project.

What replaced GitFlow? ›

GitLab Flow is a simpler alternative to GitFlow that combines feature-driven development and feature branching with issue tracking. With GitFlow, developers create a develop branch and make that the default while GitLab Flow works with the main branch right away.

What is better than GitFlow? ›

GitHub Flow is a simpler alternative to Git Flow ideal for smaller teams as they don't need to manage multiple versions. Unlike Git Flow, this model doesn't have release branches.

What is the most common git workflow? ›

1. Centralized Workflow. The centralized workflow is a simple and straightforward approach to using Git. In this model, there is a single central repository with a "master" branch where all developers push their changes.

What does forking a Git repository mean? ›

A fork in Git is simply a copy of an existing repository in which the new owner disconnects the codebase from previous committers. A fork often occurs when a developer becomes dissatisfied or disillusioned with the direction of a project and wants to detach their work from that of the original project.

What is the forking function? ›

The fork() function creates a new process. The new process (child process) is an exact copy of the calling process (parent process) except as detailed below. The child process has a unique process ID. The child process ID also does not match any active process group ID.

Is forking good in GitHub? ›

However, if you clone someone else's repository, if you don't have write access you still cannot push any changes. Forking, on the other hand, allows you to make changes to the code without affecting the original repo.

What does forking a project mean? ›

In software engineering, a project fork happens when developers take a copy of source code from one software package and start independent development on it, creating a distinct and separate piece of software.

Top Articles
Can you Get Married in Fallout 76? - Playbite
What is Self-Priming Paint and Does it Work?
Ohio Houses With Land for Sale - 1,591 Properties
Where are the Best Boxing Gyms in the UK? - JD Sports
<i>1883</i>'s Isabel May Opens Up About the <i>Yellowstone</i> Prequel
Dr Doe's Chemistry Quiz Answer Key
Puretalkusa.com/Amac
Trade Chart Dave Richard
THE 10 BEST River Retreats for 2024/2025
Lesson 3 Homework Practice Measures Of Variation Answer Key
Slushy Beer Strain
Highland Park, Los Angeles, Neighborhood Guide
Daily Voice Tarrytown
Boston Gang Map
Ruse For Crashing Family Reunions Crossword
Myhr North Memorial
Soulstone Survivors Igg
Rochester Ny Missed Connections
Hood County Buy Sell And Trade
Greenville Sc Greyhound
Litter Robot 3 RED SOLID LIGHT
Www.craigslist.com Austin Tx
Craiglist.nj
Mdt Bus Tracker 27
Best Middle Schools In Queens Ny
Guinness World Record For Longest Imessage
Winterset Rants And Raves
Babydepot Registry
Darknet Opsec Bible 2022
Helloid Worthington Login
Haunted Mansion Showtimes Near Cinemark Tinseltown Usa And Imax
Wcostream Attack On Titan
Dumb Money, la recensione: Paul Dano e quel film biografico sul caso GameStop
Sun Haven Pufferfish
Microsoftlicentiespecialist.nl - Microcenter - ICT voor het MKB
John F Slater Funeral Home Brentwood
Instafeet Login
Ursula Creed Datasheet
How To Paint Dinos In Ark
Koninklijk Theater Tuschinski
Tsbarbiespanishxxl
Achieving and Maintaining 10% Body Fat
How Big Is 776 000 Acres On A Map
Penny Paws San Antonio Photos
The Bold and the Beautiful
A jovem que batizou lei após ser sequestrada por 'amigo virtual'
300+ Unique Hair Salon Names 2024
Julies Freebies Instant Win
Cvs Minute Clinic Women's Services
Service Changes and Self-Service Options
Used Curio Cabinets For Sale Near Me
What Responsibilities Are Listed In Duties 2 3 And 4
Latest Posts
Article information

Author: Gov. Deandrea McKenzie

Last Updated:

Views: 5915

Rating: 4.6 / 5 (66 voted)

Reviews: 89% of readers found this page helpful

Author information

Name: Gov. Deandrea McKenzie

Birthday: 2001-01-17

Address: Suite 769 2454 Marsha Coves, Debbieton, MS 95002

Phone: +813077629322

Job: Real-Estate Executive

Hobby: Archery, Metal detecting, Kitesurfing, Genealogy, Kitesurfing, Calligraphy, Roller skating

Introduction: My name is Gov. Deandrea McKenzie, I am a spotless, clean, glamorous, sparkling, adventurous, nice, brainy person who loves writing and wants to share my knowledge and understanding with you.