<?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: William Otieno</title>
    <description>The latest articles on DEV Community by William Otieno (@williamotieno).</description>
    <link>https://dev.to/williamotieno</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.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F470859%2F81f9b710-d3e5-4f9d-8064-42f7cd7d4069.jpeg</url>
      <title>DEV Community: William Otieno</title>
      <link>https://dev.to/williamotieno</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/williamotieno"/>
    <language>en</language>
    <item>
      <title>Beginner's guide to Git and Open-Source Contribution</title>
      <dc:creator>William Otieno</dc:creator>
      <pubDate>Sat, 17 Oct 2020 15:22:08 +0000</pubDate>
      <link>https://dev.to/williamotieno/beginner-s-guide-to-git-and-open-source-contribution-34h</link>
      <guid>https://dev.to/williamotieno/beginner-s-guide-to-git-and-open-source-contribution-34h</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;There are a lot of skilled developers from around the world; ranging from web developers, android engineers, DevOps engineers, sys admins, IoT devs to simple script kiddies...but there is always one thing that ties them down; getting 3rd-party assistance. That's where open-source contribution comes in.&lt;br&gt;
Well, there are a number of definitions regarding what open source is, Wikipedia defining it as "denoting software for which the original source code is made freely available and may be redistributed and modified" but I see it more as software of the people, for the people and by the people. &lt;/p&gt;

&lt;p&gt;In order for software developers and engineers to contribute to particular projects without the need to be physically present, a version control system (VCS) was developed. Well, it's not only about remote contribution; just as the name suggests, version control also enables one to revert back to a particular moment in time just in case he/she made a mistake developing software. Over the years there have been a number of VCS that were implemented but Git became the most popular. &lt;/p&gt;

&lt;p&gt;This article will focus on the absolute beginners, we will go through the fundamentals only as Git is very wide. But not to worry, you will have mastered essentials in just a couple of minutes.&lt;/p&gt;
&lt;h3&gt;
  
  
  What is Version Control?
&lt;/h3&gt;

&lt;p&gt;When you are working on a simple project, such as a single page html, it is fairly easy to remember the last thing you changed and where the development is headed. But tracking revisions over time, also referred to as version control, quickly becomes more complex when you are working on a large project with multiple files and multiple developers. &lt;/p&gt;

&lt;p&gt;You not only want to record changes, but also who made the changes, and when. Managing revisions at this level requires a version control system. &lt;/p&gt;

&lt;p&gt;Version Control Systems (VCS) help a software team manage changes to source code over time.&lt;br&gt;&lt;br&gt;
VCS software includes tools for saving the state of a project, viewing the history of changes, and reverting changes.&lt;br&gt;&lt;br&gt;
Developing software without using version control is risky, similar to not having backups. &lt;/p&gt;

&lt;p&gt;VCS can also enhance and speed up development. Depending on the version control software used, many developers can work on the same code at the same time. &lt;br&gt;
For example, one developer on the team may be working on a new feature while another developer fixes an unrelated bug, each developer making their changes in several parts of the code base.  &lt;/p&gt;

&lt;p&gt;VCS even have tools to prevent conflicts when one developer's changes are incompatible with changes made at the same time by another developer.&lt;/p&gt;
&lt;h3&gt;
  
  
  Git vs Github
&lt;/h3&gt;

&lt;p&gt;Git became the most popular VCS system since its onset in 2005. It was made mainly as a result of necessity since a lot of developers needed to contribute to the Linux Kernel. It's main advantage was that it was distributed - rather than having only one single place for the full version history of a project, every developer's working copy of the code is also a repository that can contain the full history of all changes. &lt;/p&gt;

&lt;p&gt;You should however note that &lt;a href="https://git-scm.com/" rel="noopener noreferrer"&gt;Git&lt;/a&gt; is somewhat like an engine and &lt;a href="https://github.com/" rel="noopener noreferrer"&gt;Github&lt;/a&gt; is a platform that enables users to exploit git.&lt;/p&gt;
&lt;h3&gt;
  
  
  Hands-on Lab
&lt;/h3&gt;
&lt;h4&gt;
  
  
  Getting Git
&lt;/h4&gt;

&lt;p&gt;For *nix systems(Mac/Linux), git should be installed in your system by default. If not, there is a quick installation guide for all platforms &lt;a href="https://git-scm.com/book/en/v2/Getting-Started-Installing-Git" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;h4&gt;
  
  
  Initializing a Git repository
&lt;/h4&gt;

&lt;p&gt;I'll try to explain how this works in the simplest form. This is how everything is... You have a local repository (storage) and a remote repository. The local repo is essentially in your computer and the remote repo is online in a particular platform (maybe Github or Gitlab). So what happens is that you will mostly write code on your local machine then push those changes to the remote repo where other members can see what you did and in essence pull those changes from the remote repo to there local repos. It's just like uploading and downloading in a way. &lt;/p&gt;

&lt;p&gt;Let's just jump right in for this to make sense.&lt;br&gt;
We will first create a directory(folder) then make it a local git repository so that git can track every change happening to it.&lt;/p&gt;

&lt;p&gt;Launch your command-line interface (terminal for *nix users and the git command-line for Windows users)&lt;br&gt;
To create folder, it's just as simple as running &lt;code&gt;mkdir foldername&lt;/code&gt;&lt;br&gt;
Let's name it &lt;code&gt;devstuff&lt;/code&gt;&lt;br&gt;
As of now, it is just a folder named so. We then have to further make it a git repository (like a git storage). We do this by navigating into the folder using the &lt;code&gt;cd&lt;/code&gt; command and executing &lt;code&gt;git init&lt;/code&gt; (initialize git repo)&lt;br&gt;
So in my terminal...&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fs0z0po0ro6xrtfx2qtxu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fs0z0po0ro6xrtfx2qtxu.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;
As you can see, we got into the directory and it was at first just a directory. After initializing git, it becomes a git repo. What it does is that it creates a git folder of sorts but it is hidden by default hence named &lt;code&gt;.git&lt;/code&gt; as seen by the generated path above.&lt;br&gt;
Well, we now have our local git repo. Let's make a remote repo on Github then connect it to our local repo.&lt;br&gt;
You should first create an account on Github and sign in.&lt;br&gt;
Navigate to the top right corner and click on the &lt;code&gt;+&lt;/code&gt; button and select &lt;code&gt;New Repository&lt;/code&gt; &lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fqiy5soke1ce313uz18s6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fqiy5soke1ce313uz18s6.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;
For ease, we shall give it the same name as our local repo &lt;code&gt;devstuff&lt;/code&gt; and put in some little description and create the repo.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fgsn0mxgwikt1xb9j7jn4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fgsn0mxgwikt1xb9j7jn4.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;
You should encounter a new page with this...&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fvl6ys4wyh5yfh4qlov0m.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fvl6ys4wyh5yfh4qlov0m.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;
Let's break down what we can see then...&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fm3mfq8bmnexl0jh4z0ju.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fm3mfq8bmnexl0jh4z0ju.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;
Well, we already did most of the essential stuff on our own so the only command we should run is &lt;code&gt;git remote add origin https://github.com/WilliamOtieno/devstuff.git&lt;/code&gt;&lt;br&gt;
That will simply link our local repo to our remote one. In short, we are adding the remote repo from origin to our local repo. So that information will be contained in the &lt;code&gt;.git&lt;/code&gt; hidden directory. &lt;br&gt;
In our terminal...&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fo2imn3r92i7nl4ub97y6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fo2imn3r92i7nl4ub97y6.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;
Let's add a file so that we can track the changes. You can use your file manager to do so or in the terminal execute &lt;code&gt;touch dev.py&lt;/code&gt;&lt;br&gt;
It will be some simple Python code with a simple print statement.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fhjkbzjnoomg6pvukhqvg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fhjkbzjnoomg6pvukhqvg.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;
Running a simple listing &lt;code&gt;ls&lt;/code&gt; command shows that our file is present. &lt;br&gt;
We can take it a notch higher by running &lt;code&gt;git status&lt;/code&gt; to see...well, the command is self-explanatory&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fv8x1ua7jz63r2vi3yc6s.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fv8x1ua7jz63r2vi3yc6s.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h4&gt;
  
  
  Git Tracking
&lt;/h4&gt;

&lt;p&gt;When working with files, git by itself has a particular workflow to get things done. There are 3 states in which a file exists:-&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Untracked&lt;/li&gt;
&lt;li&gt;Staged&lt;/li&gt;
&lt;li&gt;Committed&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Finding the actual status of files opts us to implement the &lt;code&gt;git status&lt;/code&gt; command as seen earlier. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Untracked&lt;/strong&gt; means that git is not currently tracking any changes on the file, &lt;strong&gt;staged&lt;/strong&gt; means that git is tracking changes on the file wheareas &lt;strong&gt;committed&lt;/strong&gt; means that a snapshot of the current state of the file has been taken with a simple message (commit message) of what happened in particular.&lt;br&gt;
Let's add 2 other files so that we can really understand what's going on. For that, use your file manager or simply use the &lt;code&gt;touch [filename]&lt;/code&gt; command. I'll add a &lt;code&gt;README.md&lt;/code&gt; file and maybe a &lt;code&gt;requirements.txt&lt;/code&gt; file.&lt;br&gt;
Now, to essentially move a file from the unstaged/untracked area to the staging area, we should use the &lt;code&gt;git add [filename]&lt;/code&gt; command. In your CLI...&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fyn9ccmti4b0083oioe8y.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fyn9ccmti4b0083oioe8y.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As we can see, we staged our &lt;code&gt;python&lt;/code&gt; file but the other ones remained in the unstaged area. So after staging, we should commit our change. We do this by running &lt;code&gt;git commit -m ['message']&lt;/code&gt;. In our case...&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fqfxps9hgy8ahbdc3o7gj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fqfxps9hgy8ahbdc3o7gj.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;
You should however note that commits are only applied to files on the staging area. The remaining ones remained untracked. &lt;br&gt;
Most times one will be working with dozens of files so to add all untracked files in the local git repo to the staging area, we implement &lt;code&gt;git add .&lt;/code&gt;&lt;br&gt;
&lt;strong&gt;Take note of the position of the dot.&lt;/strong&gt;&lt;br&gt;
This will add everything in the current working directory so it's like adding all the contents of the working directory. Another command would be &lt;code&gt;git add *&lt;/code&gt; which in essence means adding everything. Let's try it in our command-line and check the status...&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F802j9ahi9afed422g7ha.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F802j9ahi9afed422g7ha.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;
Let's try writing something to our &lt;code&gt;README.md&lt;/code&gt; file then check the status. You can use your favorite text editor or do this one-line command in &lt;code&gt;bash&lt;/code&gt;... &lt;br&gt;
&lt;code&gt;echo "### I love Git." &amp;gt;&amp;gt; README.md&lt;/code&gt;&lt;br&gt;
That will simply print out the text but redirect the output to the &lt;code&gt;README.md&lt;/code&gt; file thence writing to it.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F4giedpkkcibpm8wn8yyg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F4giedpkkcibpm8wn8yyg.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;
As you can see, the file was being tracked. Git has automatically detected that it was modified so we have to commit our change using the &lt;code&gt;git commit&lt;/code&gt; command.&lt;br&gt;
Consider a situation where you had staged all files in a repo and you simply want to unstage it so that git doesn't track any changes. For that scenario, one should exploit the &lt;code&gt;git rm --cached [file]&lt;/code&gt; command. In our case, let's unstage the &lt;code&gt;requirements.txt&lt;/code&gt; file and check the status.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Flrdzpwwarfvt7wns2hig.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Flrdzpwwarfvt7wns2hig.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;
Now our &lt;code&gt;requirements.txt&lt;/code&gt; file is untracked. &lt;br&gt;
But constantly having to see that portion telling us that a file is untracked  when we want it that way is rather annoying so let's consider a scenario where we do not want git to track some files. For that we use a &lt;code&gt;.gitignore&lt;/code&gt; file. It is normally hidden and doesn't have a file extension. So let's create and use it. In your CLI, just use the &lt;code&gt;touch .gitignore&lt;/code&gt; command. Or in your file manager, create a file and name it &lt;code&gt;.gitignore&lt;/code&gt; but don't append any file extension to it plus don't forget the preceding dot. &lt;br&gt;
After that, open the file and just write the name of the file(s) you want git to ignore. For multiple files, each file name should be in its own line. &lt;br&gt;
Since &lt;code&gt;.gitignore&lt;/code&gt; is a new file, stage it and commit the changes and then run the status check again.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fffaxl9i8wczo33vkf2pb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fffaxl9i8wczo33vkf2pb.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h4&gt;
  
  
  Pushing to the remote repo
&lt;/h4&gt;

&lt;p&gt;At this point, we are ready to push our changes to our remote repo in Github. But before that, I'm sure you have questions about the output from our last command &lt;code&gt;"On branch master..."&lt;/code&gt;&lt;br&gt;
Well, that will be on the next article but basically, git organizes repositories in branches such that one can avoid messing up the production or main branch. By default, the main branch is normally called &lt;code&gt;master&lt;/code&gt; and that's why it's there. Not to worry, it's nothing complicated. &lt;br&gt;
So let's push everything we've done so far to our remote repo. But at first, we shall verify that we indeed have nothing there. So go to Github and search for the repo (we named it &lt;code&gt;devstuff&lt;/code&gt;). &lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fi95gwir8bnseuk9q39xm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fi95gwir8bnseuk9q39xm.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;
As you can see, there is no code but some guide to get started. But before that, we should set up our credentials in our git command-line before pushing. You should use the same name and email address as the ones in your Github account. &lt;br&gt;
Do so by running...&lt;br&gt;
&lt;code&gt;git config --global user.name "YourName"&lt;/code&gt;&lt;br&gt;
&lt;code&gt;git config --global user.email"youremail@yourdomain.com"&lt;/code&gt;&lt;br&gt;
Now let's push the code. It will be a simple one-line command...&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;git push -u origin master&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;You'll be prompted for your username and password. The password field is normally blank when typing for security reasons so don't be alarmed. &lt;br&gt;
The &lt;code&gt;-u&lt;/code&gt; flag is used to tell git that we are pushing the repo upstream and the next time we push without the flag, it should remember that we want to push upstream. Also, &lt;code&gt;origin&lt;/code&gt; is the default name of our remote repo so in essence we are pushing upstream to our remote repo called &lt;code&gt;origin&lt;/code&gt; and into the branch called &lt;code&gt;master&lt;/code&gt;.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F9z27gbjgksckgc0amn3n.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F9z27gbjgksckgc0amn3n.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;
Refresh your browser tab and voila! You'll see that the code is now present. The remote repo will contain the commit messages and commit times as well. &lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fy2m2xffyy2zvxqokyj4v.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fy2m2xffyy2zvxqokyj4v.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;
You could also click on the individual files so as to view the contents. &lt;/p&gt;

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;Git is not as complicated as people perceive it to be. This is only the 1st part of a 2-series article but the remaining chunk is not as lengthy. Actually, this is enough to get one started to open-source contribution. For any queries, just follow and send a message to my Github &lt;a href="https://github.com/WilliamOtieno/" rel="noopener noreferrer"&gt;here&lt;/a&gt;. &lt;br&gt;
Thank you for your undivided time and attention. &lt;/p&gt;

</description>
      <category>github</category>
      <category>git</category>
      <category>versioncontrol</category>
      <category>opensource</category>
    </item>
    <item>
      <title>Using Python for Arduino Projects</title>
      <dc:creator>William Otieno</dc:creator>
      <pubDate>Mon, 28 Sep 2020 17:29:03 +0000</pubDate>
      <link>https://dev.to/williamotieno/using-python-for-arduino-projects-2np</link>
      <guid>https://dev.to/williamotieno/using-python-for-arduino-projects-2np</guid>
      <description>&lt;h3&gt;
  
  
  INTRODUCTION
&lt;/h3&gt;

&lt;p&gt;Every hardware engineer and IoT enthusiast has interacted with a number of micro-controllers and embedded devices, the most common one being the Arduino micro-controller. Well, it's a good fit for noobs who want to get their feet wet but the only caveat is the C/C++ hybrid language used in the Arduino IDE as most devs find it quite intimidating. &lt;br&gt;
Today, I'm going to take you down the rabbit hole with me by showing you how to use Python to program your Arduino micro-controller.&lt;/p&gt;

&lt;h4&gt;
  
  
  REQUIREMENTS
&lt;/h4&gt;

&lt;p&gt;For starters, you'll need the following hardware:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Arduino (UNO, Mega2560...etc)&lt;/li&gt;
&lt;li&gt;Arduino USB Cable&lt;/li&gt;
&lt;li&gt;LEDs&lt;/li&gt;
&lt;li&gt;Push Button&lt;/li&gt;
&lt;li&gt;10kOhm Resistors&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Well, the only software requirement is the &lt;a href="https://www.arduino.cc/en/Main/Software" rel="noopener noreferrer"&gt;Arduino IDE&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  EXPLANATION
&lt;/h4&gt;

&lt;p&gt;The theory behind what we are trying to do is communicating with the Arduino using a serial connection between our computer and the micro-controller itself. There are a number of ways this can be achieved; in Python for example, the &lt;a href="https://pypi.org/project/pyserial/" rel="noopener noreferrer"&gt;PySerial&lt;/a&gt; library can come in handy, effectively capturing serial data transmitted between the board and the computer. But that's an article for another day.&lt;/p&gt;

&lt;p&gt;In this article we are going to exploit the &lt;a href="https://www.arduino.cc/en/Reference/Firmata" rel="noopener noreferrer"&gt;Firmata&lt;/a&gt; protocol which is already available by default in the Arduino IDE post-installation. This protocol establishes a serial communication format that allows you to read digital and analog inputs, as well as send information to digital and analog outputs. &lt;/p&gt;

&lt;h4&gt;
  
  
  Uploading the Firmata Sketch
&lt;/h4&gt;

&lt;p&gt;Let's dive right  in and see what we can do. The Firmata sketch is (as I said earlier) already available in the Arduino IDE so on your desktop, launch the IDE and navigate to &lt;em&gt;File&lt;/em&gt; then &lt;em&gt;Examples&lt;/em&gt; then &lt;em&gt;Firmata&lt;/em&gt; and click on the &lt;em&gt;StandardFirmata&lt;/em&gt; sketch.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F3p37an7ovhgbzoxzgk8g.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F3p37an7ovhgbzoxzgk8g.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;
An alternative window will be opened upon which you should select your appropriate board type and port after connecting your board to your computer via a USB cable. Compile the sketch and upload.&lt;/p&gt;

&lt;h4&gt;
  
  
  Python Fun
&lt;/h4&gt;

&lt;p&gt;Now let's play with some Python code. You will need to install the &lt;code&gt;pyFirmata&lt;/code&gt; package through the Python Package manager, &lt;code&gt;pip&lt;/code&gt;. Now, for *nix systems i.e (MacOS/Linux) launch your terminal and for Windows users, launch your command prompt then run the following command: &lt;br&gt;
&lt;code&gt;pip install pyfirmata&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;You should get some result similar to this...&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fbbf4iulymqt2onui2007.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fbbf4iulymqt2onui2007.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After installation, launch your favorite text editor, in my case, I'll write the Python code on an open-source version of VS Code. We'll now write some simple Python code equivalent to the Blink Sketch (The Hello World of Arduino😉).&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fvqggef10uadyjwrnjqnf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fvqggef10uadyjwrnjqnf.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now let's crack every bit of the code (pun intended😉).&lt;br&gt;
So we first import the library we need to establish a serial connection between our board and the computer. Our plan is to control the inbuilt LED connected to pin 13 on the board so it will be prudent to use the time module in order to control how long we will turn the LED on/off.&lt;/p&gt;

&lt;p&gt;Since communication is through a serial protocol, we need to define our port. You can get this info from the Arduino IDE and for my case it is as stipulated above. For Windows users, it may be &lt;code&gt;COMx&lt;/code&gt; where x is any integer.&lt;br&gt;
We then instantiate our board object (&lt;code&gt;myBoard&lt;/code&gt;) and pass the port as an argument to &lt;code&gt;pyfirmata.Arduino()&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The next step is to run the main block of code in a loop just like in the Arduino syntax. So let's use a &lt;code&gt;while&lt;/code&gt; loop for that...&lt;br&gt;
&lt;code&gt;board.digital&lt;/code&gt; is a Python list containing all the digital pins of the Arduino but in our case we are using pin 13. The &lt;code&gt;.write()&lt;/code&gt; method is used to write the state to the digital pin. The state is represented as either 1 or 0 for &lt;code&gt;HIGH&lt;/code&gt; or &lt;code&gt;LOW&lt;/code&gt; respectively. The former representing 5V and the latter 0V hence high or low.&lt;br&gt;
The &lt;code&gt;HIGH&lt;/code&gt; state provides 5V to the LED and turns it on while &lt;code&gt;LOW&lt;/code&gt; state provides 0V hence turning it off. The &lt;code&gt;.sleep()&lt;/code&gt; method from the &lt;code&gt;time&lt;/code&gt; module is responsible for handling how long each action takes; just like the &lt;code&gt;delay()&lt;/code&gt; function in the Arduino syntax. &lt;/p&gt;

&lt;h4&gt;
  
  
  Running the Code
&lt;/h4&gt;

&lt;p&gt;We can now run the code by launching a terminal and executing:&lt;br&gt;
&lt;code&gt;python pyduino.py&lt;/code&gt;&lt;br&gt;
You should however note that the proper syntax is:&lt;br&gt;
&lt;code&gt;python [filename.py]&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Now wasn't that simple. Let's go even deeper by adding a push button that will change the state of our digital pin...&lt;/p&gt;

&lt;h4&gt;
  
  
  More Hands-on Experience
&lt;/h4&gt;

&lt;p&gt;We shall first connect our circuit as follows:-&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fotgygzwhy8hzz2lfne9a.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fotgygzwhy8hzz2lfne9a.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The Button is connected to a 10k pull down resistor so as to ensure the voltage is completely pulled down to 0V on the digital pin.&lt;/p&gt;

&lt;p&gt;Our code will only change a bit and it will be just as simple as the other one:&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F9m2ac9yxuh71e4r52m0a.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F9m2ac9yxuh71e4r52m0a.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We are conversant with line 1 through 5. Line 6 is used to define an iterator that will constantly read the state of our digital pins. Line 7 only instantiates or activates it.&lt;br&gt;
Line 9 explicitly declares digital pin 10 as output through the &lt;code&gt;pyfirmata.INPUT&lt;/code&gt; method. This is necessary since the default config use for digital pins is as output and not input.&lt;/p&gt;

&lt;p&gt;We then go to our loop and define our switch pin. The rest is as intuitive as it gets.&lt;br&gt;
The final step is obviously running our Python script and Voila! Some action. &lt;/p&gt;

&lt;h3&gt;
  
  
  CONCLUSION
&lt;/h3&gt;

&lt;p&gt;Micro-controllers and Embedded Devices are on the rise in numerous applications especially in the Internet of Things(IoT). Enthusiasts, hobbyists, Engineers, and other developers are getting the chance to explore numerous possibilities by building projects and contributing to others. &lt;br&gt;
For the Arduino fans, this article is only a tip of the iceberg. The journey is a deep dark rabbit hole that once you get yourself into, there's no turning back. This also applies to Python programmers who just don't like C/C++. &lt;br&gt;
For those interested in learning more, there is excellent documentation on Pyfirmata &lt;a href="https://pypi.org/project/pyFirmata/" rel="noopener noreferrer"&gt;here&lt;/a&gt; that  will be of great use. &lt;br&gt;
For those who want to do IoT natively in Python, then there are other Micro-controllers such as &lt;a href="https://micropython.org/" rel="noopener noreferrer"&gt;MicroPython&lt;/a&gt; and the renowned &lt;a href="https://www.raspberrypi.org/" rel="noopener noreferrer"&gt;RaspberryPi&lt;/a&gt;. But baby steps first😅; we all start from somewhere.&lt;/p&gt;

&lt;p&gt;Anyway, that's all for now. I hope you enjoyed.&lt;br&gt;
Thank you.&lt;/p&gt;

</description>
      <category>arduino</category>
      <category>python</category>
      <category>iot</category>
      <category>microcontroller</category>
    </item>
  </channel>
</rss>
