Sick Gaming
[Tut] GitHub Fork and Pull Workflow - Printable Version

+- Sick Gaming (https://www.sickgaming.net)
+-- Forum: Programming (https://www.sickgaming.net/forum-76.html)
+--- Forum: Python (https://www.sickgaming.net/forum-83.html)
+--- Thread: [Tut] GitHub Fork and Pull Workflow (/thread-100738.html)



[Tut] GitHub Fork and Pull Workflow - xSicKxBot - 02-12-2023

GitHub Fork and Pull Workflow

<div>
<div class="kk-star-ratings kksr-auto kksr-align-left kksr-valign-top" data-payload='{&quot;align&quot;:&quot;left&quot;,&quot;id&quot;:&quot;1125760&quot;,&quot;slug&quot;:&quot;default&quot;,&quot;valign&quot;:&quot;top&quot;,&quot;ignore&quot;:&quot;&quot;,&quot;reference&quot;:&quot;auto&quot;,&quot;class&quot;:&quot;&quot;,&quot;count&quot;:&quot;1&quot;,&quot;legendonly&quot;:&quot;&quot;,&quot;readonly&quot;:&quot;&quot;,&quot;score&quot;:&quot;5&quot;,&quot;starsonly&quot;:&quot;&quot;,&quot;best&quot;:&quot;5&quot;,&quot;gap&quot;:&quot;5&quot;,&quot;greet&quot;:&quot;Rate this post&quot;,&quot;legend&quot;:&quot;5\/5 - (1 vote)&quot;,&quot;size&quot;:&quot;24&quot;,&quot;width&quot;:&quot;142.5&quot;,&quot;_legend&quot;:&quot;{score}\/{best} - ({count} {votes})&quot;,&quot;font_factor&quot;:&quot;1.25&quot;}'>
<div class="kksr-stars">
<div class="kksr-stars-inactive">
<div class="kksr-star" data-star="1" style="padding-right: 5px">
<div class="kksr-icon" style="width: 24px; height: 24px;"></div>
</p></div>
<div class="kksr-star" data-star="2" style="padding-right: 5px">
<div class="kksr-icon" style="width: 24px; height: 24px;"></div>
</p></div>
<div class="kksr-star" data-star="3" style="padding-right: 5px">
<div class="kksr-icon" style="width: 24px; height: 24px;"></div>
</p></div>
<div class="kksr-star" data-star="4" style="padding-right: 5px">
<div class="kksr-icon" style="width: 24px; height: 24px;"></div>
</p></div>
<div class="kksr-star" data-star="5" style="padding-right: 5px">
<div class="kksr-icon" style="width: 24px; height: 24px;"></div>
</p></div>
</p></div>
<div class="kksr-stars-active" style="width: 142.5px;">
<div class="kksr-star" style="padding-right: 5px">
<div class="kksr-icon" style="width: 24px; height: 24px;"></div>
</p></div>
<div class="kksr-star" style="padding-right: 5px">
<div class="kksr-icon" style="width: 24px; height: 24px;"></div>
</p></div>
<div class="kksr-star" style="padding-right: 5px">
<div class="kksr-icon" style="width: 24px; height: 24px;"></div>
</p></div>
<div class="kksr-star" style="padding-right: 5px">
<div class="kksr-icon" style="width: 24px; height: 24px;"></div>
</p></div>
<div class="kksr-star" style="padding-right: 5px">
<div class="kksr-icon" style="width: 24px; height: 24px;"></div>
</p></div>
</p></div>
</div>
<div class="kksr-legend" style="font-size: 19.2px;"> 5/5 – (1 vote) </div>
</p></div>
<p>If you are unfamiliar with <code>git</code> 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).</p>
<p>This post will focus on the common<strong> fork and pull workflow</strong> model that is used by many GitHub repositories. It will provide the necessary <code>git</code> commands and a short description for each step of the workflow, specifically for Git beginners who may be hesitant to contribute to GitHub.</p>
<p class="has-base-background-color has-background"><img src="https://s.w.org/images/core/emoji/14.0.0/72x72/1f4a1.png" alt="?" class="wp-smiley" style="height: 1em; max-height: 1em;" /> <strong>Definition</strong>: A repository is a central location that holds data. It’s mostly used to store and manage code, documents, images, videos, and other data types. Repositories can be either public or private and are often used by software developers to store and collaborate on projects.</p>
<h2>Fork and Pull Workflow In a Nutshell</h2>
<div class="wp-block-image">
<figure class="aligncenter size-large"><img loading="lazy" decoding="async" width="1024" height="309" src="https://blog.finxter.com/wp-content/uploads/2023/02/image-167-1024x309.png" alt="" class="wp-image-1125780" srcset="https://blog.finxter.com/wp-content/uploads/2023/02/image-167-1024x309.png 1024w, https://blog.finxter.com/wp-content/uploads/2023/02/image-167-300x91.png 300w, https://blog.finxter.com/wp-content/uploads/2023/02/image-167-768x232.png 768w, https://blog.finxter.com/wp-content/uploads/2023/02/image-167.png 1093w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>
</div>
<p>The <strong>“Fork &amp; Pull” workflow </strong>is a way to contribute changes to an original repository using three easy steps: </p>
<ul>
<li><strong>Step 1: </strong>create a personal copy (fork) of the repository, </li>
<li><strong>Step 2: </strong>edit the fork, and </li>
<li><strong>Step 3: </strong>submit a request (pull request) to the owner of the original repository to merge your changes. </li>
</ul>
<h3>Step 1: Create a Fork</h3>
<p class="has-base-background-color has-background"><img src="https://s.w.org/images/core/emoji/14.0.0/72x72/1f4a1.png" alt="?" class="wp-smiley" style="height: 1em; max-height: 1em;" /> <strong>Definition</strong>: A fork is a copy of a repository. Forking a repository allows you to freely experiment with changes without affecting the original project. Forks are commonly used to either propose changes to someone else’s project or to use someone else’s project as a starting point for your own idea.</p>
<p>Creating a fork on GitHub is easy – just click the “<strong>Fork</strong>” button on the repository page. </p>
<p>Here’s how forking the TensorFlow repository looks like — easy:</p>
<figure class="wp-block-image size-full"><img decoding="async" loading="lazy" width="1099" height="614" src="https://blog.finxter.com/wp-content/uploads/2023/02/fork_repos.gif" alt="" class="wp-image-1125779"/></figure>
<h3>Step 2: Clone and Edit Fork</h3>
<p>Once you have your fork, you can clone it to your local machine and edit it.</p>
<p>Here’s where you actually change or add code files, find and remove bugs, write comments for the code, or refactor everything.</p>
<p class="has-base-background-color has-background"><img src="https://s.w.org/images/core/emoji/14.0.0/72x72/1f4a1.png" alt="?" class="wp-smiley" style="height: 1em; max-height: 1em;" /> <strong>Definition</strong>: If you clone a Git repository, you essentially create an identical copy. You clone to work on your own local copy of the repository and sync changes back to the original repository. This is useful for keeping your local copy up to date with the latest changes and for contributing changes back to the original repository.</p>
<h3>Step 3: Push Changes to Fork and Perform Pull Request</h3>
<p>When you are done, you push your changes back to the fork on GitHub.</p>
<p class="has-base-background-color has-background"><img src="https://s.w.org/images/core/emoji/14.0.0/72x72/1f4a1.png" alt="?" class="wp-smiley" style="height: 1em; max-height: 1em;" /> <strong>Definition</strong>: A Git push operation is the process of sending changes from a local repository to a remote repository. The changes are applied to the remote repository. And your local repository is synchronized with the remote repository.</p>
<p>Lastly, you submit a <strong>pull request</strong> to the owner of the original repository. </p>
<div class="wp-block-image">
<figure class="aligncenter size-large"><img decoding="async" loading="lazy" width="1024" height="297" src="https://blog.finxter.com/wp-content/uploads/2023/02/image-168-1024x297.png" alt="" class="wp-image-1125782" srcset="https://blog.finxter.com/wp-content/uploads/2023/02/image-168-1024x297.png 1024w, https://blog.finxter.com/wp-content/uploads/2023/02/image-168-300x87.png 300w, https://blog.finxter.com/wp-content/uploads/2023/02/image-168-768x223.png 768w, https://blog.finxter.com/wp-content/uploads/2023/02/image-168-1536x445.png 1536w, https://blog.finxter.com/wp-content/uploads/2023/02/image-168.png 1818w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>
</div>
<p class="has-base-background-color has-background"><img src="https://s.w.org/images/core/emoji/14.0.0/72x72/1f4a1.png" alt="?" class="wp-smiley" style="height: 1em; max-height: 1em;" /> <strong>Definition</strong>: A pull request is a request to merge a branch into the main branch of a repository. It is used to propose changes and request feedback from other contributors, who can accept or reject the changes based on their review.</p>
<p>If there are no merge conflicts, the owner can simply click the “<strong>merge</strong>” button to accept your changes.</p>
<h2>Six Steps to Pull Request</h2>
<p>To create a pull request, you need to:</p>
<ol>
<li>Fork the repository on GitHub.</li>
<li>Clone your fork to your workspace with the <code>git clone</code> command.</li>
<li>Modify the code and commit the changes to your local clone.</li>
<li>Push your changes to your remote fork on GitHub.</li>
<li>Create a pull request on GitHub and wait for the owner to merge or comment your changes.</li>
<li>If the owner suggests changes, push them to your fork, and the pull request will be updated automatically.</li>
</ol>
<h2>What If Multiple Devs Work In Parallel?</h2>
<p>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.</p>
<p>Here’s my drawing of this scenario. <img src="https://s.w.org/images/core/emoji/14.0.0/72x72/1f606.png" alt="?" class="wp-smiley" style="height: 1em; max-height: 1em;" /></p>
<div class="wp-block-image">
<figure class="aligncenter size-full"><img decoding="async" loading="lazy" width="370" height="241" src="https://blog.finxter.com/wp-content/uploads/2023/02/image-166.png" alt="" class="wp-image-1125765" srcset="https://blog.finxter.com/wp-content/uploads/2023/02/image-166.png 370w, https://blog.finxter.com/wp-content/uploads/2023/02/image-166-300x195.png 300w" sizes="(max-width: 370px) 100vw, 370px" /></figure>
</div>
<p>Add the original repository as a remote repository called “upstream”:</p>
<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">git remote add upstream https://github.com/OWNER/REPOSITORY.git</pre>
<p>Fetch all changes from the upstream repository:</p>
<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">git fetch upstream</pre>
<p>Switch to the master branch of your fork:</p>
<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">git checkout master</pre>
<p>Merge changes from the upstream repository into your fork:</p>
<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">git merge upstream/master</pre>
<p>If you are working on multiple features, you should isolate them from each other. To do this, create a separate branch for each feature. </p>
<ul>
<li>Use the command <code>git checkout -b BRANCHNAME</code> to create and switch to a new branch. </li>
<li>Upload the branch to the remote fork with <code>git push --set-upstream origin BRANCHNAME</code>. </li>
<li>To switch between branches, use <code>git checkout BRANCHNAME</code>. </li>
<li>To create a pull request from a branch, go to the GitHub page of that branch and click the “pull request” button.</li>
</ul>
<p>To update a feature branch:</p>
<ol>
<li>Switch to the feature branch: <code>git checkout my-feature-branch</code></li>
<li>Commit all changes: <code>git commit -m MESSAGE</code></li>
<li>Update the feature branch by rebasing it from the master branch: <code>git rebase master</code></li>
</ol>
<h2>Why I Wrote This</h2>
<div class="wp-block-image">
<figure class="aligncenter size-full"><img decoding="async" loading="lazy" width="703" height="462" src="https://blog.finxter.com/wp-content/uploads/2023/02/image-170.png" alt="" class="wp-image-1125792" srcset="https://blog.finxter.com/wp-content/uploads/2023/02/image-170.png 703w, https://blog.finxter.com/wp-content/uploads/2023/02/image-170-300x197.png 300w" sizes="(max-width: 703px) 100vw, 703px" /></figure>
</div>
<p>I wrote this short tutorial to help contributors to our real-world practical project to <strong>build a P2P social network for information dissemination</strong> 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:</p>
<p class="has-base-background-color has-background"><img src="https://s.w.org/images/core/emoji/14.0.0/72x72/1f449.png" alt="?" class="wp-smiley" style="height: 1em; max-height: 1em;" /> <strong>Recommended</strong>: <a href="https://github.com/finxter/PeerBrain" data-type="URL" data-id="https://github.com/finxter/PeerBrain" target="_blank" rel="noreferrer noopener">Peer Brain – A Decentralized P2P Social Network App</a></p>
<p><em>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! <img src="https://s.w.org/images/core/emoji/14.0.0/72x72/2934.png" alt="⤴" class="wp-smiley" style="height: 1em; max-height: 1em;" /></em></p>
<h2>Summary</h2>
<p>The <strong>Fork and Pull Workflow</strong> is a popular collaboration model used during software development. </p>
<p>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.</p>
<p>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.</p>
<p>The <strong>Fork and Pull Workflow</strong> 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. </p>
<p>This workflow also benefits upstream maintainers, as they don’t have to manage multiple contributions coming in from multiple sources.</p>
<p class="has-base-background-color has-background"><img src="https://s.w.org/images/core/emoji/14.0.0/72x72/1f449.png" alt="?" class="wp-smiley" style="height: 1em; max-height: 1em;" /> <strong>Recommended</strong>: <a href="https://github.com/finxter/PeerBrain" data-type="URL" data-id="https://github.com/finxter/PeerBrain" target="_blank" rel="noreferrer noopener">Peer Brain – A Decentralized P2P Social Network App</a></p>
</div>


https://www.sickgaming.net/blog/2023/02/11/github-fork-and-pull-workflow/