<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Adam Reidelbach</title>
    <description>The latest articles on DEV Community by Adam Reidelbach (@adamreidelbach).</description>
    <link>https://dev.to/adamreidelbach</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F120819%2Fb58ee9b9-1206-43f1-8b75-b2911d605a55.jpg</url>
      <title>DEV Community: Adam Reidelbach</title>
      <link>https://dev.to/adamreidelbach</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/adamreidelbach"/>
    <language>en</language>
    <item>
      <title>Open Source Git Workflow (an overview)</title>
      <dc:creator>Adam Reidelbach</dc:creator>
      <pubDate>Wed, 29 May 2019 19:28:31 +0000</pubDate>
      <link>https://dev.to/adamreidelbach/open-source-git-workflow-an-overview-2oo2</link>
      <guid>https://dev.to/adamreidelbach/open-source-git-workflow-an-overview-2oo2</guid>
      <description>&lt;p&gt;&lt;em&gt;This tutorial assumes a basic understanding of git. Including creating branches, adding / committing code, and creating pull requests.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Prior to my current role, my workflow while working with git typically looked something like this:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Clone the repo.&lt;/li&gt;
&lt;li&gt;Ensure the local master is update to date, then create a branch off of master and start coding.&lt;/li&gt;
&lt;li&gt;Add, commit, and push up the branch.&lt;/li&gt;
&lt;li&gt;Check for any merge conflicts or unintended changes. Then, create a pull request for review.&lt;/li&gt;
&lt;li&gt;Rinse and repeat, starting with step 2.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In my current role, we use a pattern that is commonly used when contributing to an open source project. It uses two concepts that were not included in the previous workflow example, &lt;a href="https://help.github.com/en/articles/fork-a-repo"&gt;forks&lt;/a&gt; and &lt;a href="https://git-scm.com/book/en/v2/Git-Basics-Working-with-Remotes"&gt;remotes&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Forks
&lt;/h3&gt;

&lt;p&gt;When working with a project that you do not maintain, you likely don't have the necessary credentials to push changes directly to that repo. This is where forking comes in. You can &lt;strong&gt;&lt;em&gt;make a copy&lt;/em&gt;&lt;/strong&gt; of the repo onto our personal account and make all the changes you want, without affecting the original repo.&lt;/p&gt;

&lt;h3&gt;
  
  
  Remotes
&lt;/h3&gt;

&lt;p&gt;After you make this copy (fork) of the repo, this new location is where you will be pushing your changes. The original repo and your copy are in &lt;strong&gt;&lt;em&gt;different locations&lt;/em&gt;&lt;/strong&gt;, aka remotes.&lt;/p&gt;

&lt;h2&gt;
  
  
  TL;DR
&lt;/h2&gt;

&lt;p&gt;(In case you'd like to skip the more thorough explanation)&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Fork the repo to your desired account.&lt;/li&gt;
&lt;li&gt;Clone the forked repo locally.&lt;/li&gt;
&lt;li&gt;Add a remote that points to the original repo and name it &lt;code&gt;upstream&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Manually sync up with &lt;code&gt;upstream&lt;/code&gt; by running &lt;code&gt;get fetch upstream&lt;/code&gt; followed by &lt;code&gt;git status&lt;/code&gt; to take a look.

&lt;ul&gt;
&lt;li&gt;If necessary, pull in any changes.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Create a branch off of master and start coding.&lt;/li&gt;
&lt;li&gt;Add, commit, and push up the branch (to your fork).&lt;/li&gt;
&lt;li&gt;Check for any merge conflicts or unintended changes between your branch and the original repo's master branch. If it looks good, create a pull request.&lt;/li&gt;
&lt;li&gt;Rinse and repeat, starting with step 4.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Break It Down
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Fork the repo you'll be working with to your desired account.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://help.github.com/en/articles/cloning-a-repository"&gt;Clone&lt;/a&gt; your forked repo locally by running &lt;code&gt;git clone https://github.com/your-username/name-of-repo.git&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Navigate to your new repo with  &lt;code&gt;cd name-of-repo&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Run &lt;code&gt;git status &amp;amp;&amp;amp; git remote -v&lt;/code&gt; in your terminal and you will see the following:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;On branch master
Your branch is up to &lt;span class="nb"&gt;date &lt;/span&gt;with &lt;span class="s1"&gt;'origin/master'&lt;/span&gt;&lt;span class="nb"&gt;.&lt;/span&gt;

nothing to commit, working tree clean
origin  https://github.com/your-username/name-of-repo.git &lt;span class="o"&gt;(&lt;/span&gt;fetch&lt;span class="o"&gt;)&lt;/span&gt;
origin  https://github.com/your-username/name-of-repo.git &lt;span class="o"&gt;(&lt;/span&gt;push&lt;span class="o"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Notice that the name &lt;code&gt;origin&lt;/code&gt; is auto-generated and points at your &lt;br&gt;
fork of the repo. When you make new changes to the code base, &lt;code&gt;origin&lt;/code&gt; is where you will push them. Eventually, the original repo will have changes made to it, so you need a way to pull in these updates. In order to do so, you need to add a remote that points to it. Traditionally, we call this &lt;code&gt;upstream&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Run &lt;code&gt;git remote add upstream https://github.com/not-your-username/name-of-repo.git&lt;/code&gt;. Then &lt;code&gt;git status &amp;amp;&amp;amp; git remote -v&lt;/code&gt; once again to see the newly added remote and its location.&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;origin  https://github.com/your-username/name-of-repo.git &lt;span class="o"&gt;(&lt;/span&gt;fetch&lt;span class="o"&gt;)&lt;/span&gt;
origin  https://github.com/your-username/name-of-repo.git &lt;span class="o"&gt;(&lt;/span&gt;push&lt;span class="o"&gt;)&lt;/span&gt;
upstream  https://github.com/not-your-username/name-of-repo.git &lt;span class="o"&gt;(&lt;/span&gt;fetch&lt;span class="o"&gt;)&lt;/span&gt;
upstream  https://github.com/not-your-username/name-of-repo.git &lt;span class="o"&gt;(&lt;/span&gt;push&lt;span class="o"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Next, we need to manually sync up with &lt;code&gt;upstream&lt;/code&gt; by reaching out to it. To do this, run &lt;code&gt;git fetch upstream&lt;/code&gt;. After that, if you run &lt;code&gt;git status&lt;/code&gt;, it still says:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;On branch master
Your branch is up to &lt;span class="nb"&gt;date &lt;/span&gt;with &lt;span class="s1"&gt;'origin/master'&lt;/span&gt;&lt;span class="nb"&gt;.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Let's resolve this by ensuring our local master is pointing to &lt;code&gt;upstream&lt;/code&gt;'s master. Run &lt;code&gt;git branch --set-upstream-to=upstream/master master&lt;/code&gt; and then &lt;code&gt;git status&lt;/code&gt; once again. Since this has been recently cloned, no changes are likely, so you should see something like this:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;On branch master
Your branch is up to &lt;span class="nb"&gt;date &lt;/span&gt;with &lt;span class="s1"&gt;'upstream/master'&lt;/span&gt;&lt;span class="nb"&gt;.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;blockquote&gt;
&lt;ul&gt;
&lt;li&gt;Now that this this is setup, if your branch were to fall out of date, you can simply run &lt;code&gt;git pull&lt;/code&gt;, to pull in any changes.&lt;/li&gt;
&lt;li&gt;Additionally, I use a tool called &lt;a href="https://github.com/denysdovhan/spaceship-prompt"&gt;Spaceship Prompt&lt;/a&gt;, as it gives me some helpful visual representations of the status of my master branch, among many other features.&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
&lt;li&gt;Now that we know our local master is up to date, create a branch off of master and start coding.&lt;/li&gt;
&lt;li&gt;After you have successfully completed your changes and run any necessary tests, you can add and commit your work.&lt;/li&gt;
&lt;li&gt;Once you are ready to push up your changes, remember to push them to your forked repo. The command will look something like, &lt;code&gt;git push origin feature-branch&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Once you see your branch appear in GitHub, be sure to compare your branch with the original repo's master branch. This is where you can check for any merge conflicts that need to be resolved or any changes that perhaps you didn't intend to make. If it all looks good, make your pull request.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I hope this was helpful to you. Please feel free to reach out if you have questions or suggestions on how to improve this tutorial, or leave a comment below. You can also find me on &lt;a href="https://twitter.com/adamreidelbach"&gt;Twitter&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;I'd like to credit &lt;a href="https://twitter.com/kentcdodds/"&gt;Kent C Dodds's&lt;/a&gt; tutorial on &lt;a href="https://egghead.io/"&gt;egghead.io&lt;/a&gt; called &lt;a href="https://egghead.io/courses/how-to-contribute-to-an-open-source-project-on-github"&gt;How to Contribute to an Open Source Project on GitHub&lt;/a&gt; as well as the &lt;a href="https://git-scm.com/book/en/v2"&gt;Pro Git&lt;/a&gt; book written by &lt;a href="https://twitter.com/chacon"&gt;Scott Chacon&lt;/a&gt; and &lt;a href="https://twitter.com/benstraub"&gt;Ben Straub&lt;/a&gt;. The &lt;a href="https://git-scm.com/book/en/v2/GitHub-Contributing-to-a-Project"&gt;GitHub - Contributing to a Project&lt;/a&gt; chapter was particularly helpful. They were both great resources when putting this together and I highly suggest checking them out if you are looking for more information.&lt;/p&gt;

</description>
      <category>git</category>
      <category>beginners</category>
      <category>opensource</category>
    </item>
  </channel>
</rss>
