GitHub Fork and Pull Workflow : Chris

GitHub Fork and Pull Workflow
by: Chris
blow post content copied from  Finxter
click here to view original post


5/5 - (1 vote)

If you are unfamiliar with git and/or GitHub, it can be overwhelming navigating all the different workflow models you can use to add code to a repository. I know this feeling well, as it took me a while to get used to new workflows after being used to the classic SVN (years ago in University).

This post will focus on the common fork and pull workflow model that is used by many GitHub repositories. It will provide the necessary git commands and a short description for each step of the workflow, specifically for Git beginners who may be hesitant to contribute to GitHub.

Fork and Pull Workflow In a Nutshell

The “Fork & Pull” workflow is a way to contribute changes to an original repository using three easy steps:

  • Step 1: create a personal copy (fork) of the repository,
  • Step 2: edit the fork, and
  • Step 3: submit a request (pull request) to the owner of the original repository to merge your changes.

Step 1: Create a Fork

Creating a fork on GitHub is easy – just click the “Fork” button on the repository page.

Here’s how forking the TensorFlow repository looks like — easy:

Step 2: Clone and Edit Fork

Once you have your fork, you can clone it to your local machine and edit it.

Here’s where you actually change or add code files, find and remove bugs, write comments for the code, or refactor everything.

Step 3: Push Changes to Fork and Perform Pull Request

When you are done, you push your changes back to the fork on GitHub.

Lastly, you submit a pull request to the owner of the original repository.

If there are no merge conflicts, the owner can simply click the “merge” button to accept your changes.

Git Commands

To create a pull request, you need to:

  1. Fork the repository on GitHub.
  2. Clone your fork to your workspace with the git clone command.
  3. Modify the code and commit the changes to your local clone.
  4. Push your changes to your remote fork on GitHub.
  5. Create a pull request on GitHub and wait for the owner to merge or comment your changes.
  6. If the owner suggests changes, push them to your fork, and the pull request will be updated automatically.

What If Multiple Devs Work In Parallel?

If multiple developers work in parallel on the same repository, it may happen that they work on step 3 in parallel and try to push changes to the remote fork at the same time.

Here’s my drawing of this scenario. 😆

Add the original repository as a remote repository called “upstream”:

git remote add upstream https://github.com/OWNER/REPOSITORY.git

Fetch all changes from the upstream repository:

git fetch upstream

Switch to the master branch of your fork:

git checkout master

Merge changes from the upstream repository into your fork:

git merge upstream/master

If you are working on multiple features, you should isolate them from each other. To do this, create a separate branch for each feature.

  • Use the command git checkout -b BRANCHNAME to create and switch to a new branch.
  • Upload the branch to the remote fork with git push --set-upstream origin BRANCHNAME.
  • To switch between branches, use git checkout BRANCHNAME.
  • To create a pull request from a branch, go to the GitHub page of that branch and click the “pull request” button.

To update a feature branch:

  1. Switch to the feature branch: git checkout my-feature-branch
  2. Commit all changes: git commit -m MESSAGE
  3. Update the feature branch by rebasing it from the master branch: git rebase master

Why I Wrote This

I wrote this short tutorial to help contributors to our real-world practical project to build a P2P social network for information dissemination that is structured like a big brain. Users are neurons. Connections are synapses. Information Impulses spread through neurons “firing” and travel over synapses in a decentralized way:

👉 Recommended: Peer Brain – A Decentralized P2P Social Network App

If you like the tutorial and you want to contribute to this open-source social network app, feel free to try out this workflow yourself on this GitHub repository! ⤴

Summary

The Fork and Pull Workflow is a popular collaboration model used during software development.

In this workflow, a user forks a repository from an original (=upstream) repository, then develops and maintains a separate copy of the codebase on their own fork.

Users can then make changes to their own version of the repository, commit them, and push them up to their own fork. If the user wants to contribute their changes back to the upstream repository, they can then create a pull request. This allows the upstream maintainer to review the changes and determine if they should be merged into the main codebase.

The Fork and Pull Workflow is so popular for collaboration on a common code base because developers can work independently on the code and synchronize on the upstream repos in a well-structured and organized way.

This workflow also benefits upstream maintainers, as they don’t have to manage multiple contributions coming in from multiple sources.

👉 Recommended: Peer Brain – A Decentralized P2P Social Network App


February 12, 2023 at 02:15AM
Click here for more details...

=============================
The original post is available in Finxter by Chris
this post has been published as it is through automation. Automation script brings all the top bloggers post under a single umbrella.
The purpose of this blog, Follow the top Salesforce bloggers and collect all blogs in a single place through automation.
============================

Salesforce