<?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: Denis Ndiritu</title>
    <description>The latest articles on DEV Community by Denis Ndiritu (@sir_masha_g).</description>
    <link>https://dev.to/sir_masha_g</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%2F4071756%2F9e8394bf-5234-420e-8c28-b78440adc810.png</url>
      <title>DEV Community: Denis Ndiritu</title>
      <link>https://dev.to/sir_masha_g</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/sir_masha_g"/>
    <language>en</language>
    <item>
      <title>Understanding The Git Workflow: Working Directory, Staging, Commit and Push</title>
      <dc:creator>Denis Ndiritu</dc:creator>
      <pubDate>Sun, 23 Aug 2026 15:13:55 +0000</pubDate>
      <link>https://dev.to/sir_masha_g/understanding-the-git-workflow-working-directory-staging-commit-and-push-24b0</link>
      <guid>https://dev.to/sir_masha_g/understanding-the-git-workflow-working-directory-staging-commit-and-push-24b0</guid>
      <description>&lt;p&gt;Imagine working on a project for several weeks. You make hundreds of changes across dozens of files. Then your computer crashes. Which version of your project was working yesterday? What did you change? Which changes did your colleague make? And how do you combine everyone's work without overwriting each other's changes?&lt;/p&gt;

&lt;p&gt;This is where Git comes in.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is Git?
&lt;/h2&gt;

&lt;p&gt;Git is an open-source system that enables users to manage their projects, from a single file to large projects. Git is basically a version control system. It provides the necessary resource to help one manage files in the local machine, track the files that have been changed, attach a pointer which marks files which were changed, who did it, and when, and to make it redundant, these files can be pushed into a remote shareable project called repository in &lt;em&gt;Github&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;Git also has something very key that is called &lt;em&gt;branches&lt;/em&gt;. A branch is basically an isolated area of your project where you can work on a copy of the main project without making changes to the main work. Once you are done working on your branch, Git makes it possible to merge all the changes to the main branch.&lt;/p&gt;

&lt;p&gt;For this article, I will cover these concepts, guiding one on the step by step process of how to do all this. This article assumes that one has Git installed and configured, and has a Github account. We shall also assume that one has a text editor installed, or is conversant with commands in the terminal. We shall cover these concepts in another article.&lt;/p&gt;

&lt;h2&gt;
  
  
  Creating a Project On Your Machine
&lt;/h2&gt;

&lt;p&gt;To start, we need to create a folder where we shall be working on our project. On your machine, you can use the good old right click and select New Folder, or, if in terminal, use the command &lt;em&gt;mkdir &lt;/em&gt; as follows:&lt;br&gt;
&lt;code&gt;mkdir new_project&lt;/code&gt;&lt;br&gt;
This creates a folder called new_project&lt;/p&gt;

&lt;p&gt;We shall then open our folder in the terminal, so that we can do the following:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Initialize Git&lt;/li&gt;
&lt;li&gt;Create a file&lt;/li&gt;
&lt;li&gt;Stage it&lt;/li&gt;
&lt;li&gt;Commit it&lt;/li&gt;
&lt;li&gt;Link local repository to remote repository&lt;/li&gt;
&lt;li&gt;Push to Github account&lt;/li&gt;
&lt;/ol&gt;
&lt;h3&gt;
  
  
  Initializing Git
&lt;/h3&gt;

&lt;p&gt;At this point, we have our folder. So to open it in terminal, we can open our favorite terminal, or simply open our folder in our text editor. Once this is done, we can now initialize Git using this command:&lt;br&gt;
&lt;code&gt;git init&lt;/code&gt;&lt;br&gt;
This command simply initializes a local Git repository in your project folder. You can confirm this by confirming that we have a &lt;em&gt;.git&lt;/em&gt; folder inside our main folder. During initialization, you will note that you will be in a default branch called &lt;em&gt;main&lt;/em&gt; or &lt;em&gt;master&lt;/em&gt;. To confirm this, simply run the command:&lt;br&gt;
&lt;em&gt;git branch&lt;/em&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Creating a File
&lt;/h3&gt;

&lt;p&gt;In our terminal, we can be able to create a file using the command:&lt;br&gt;
&lt;code&gt;touch &amp;lt;filename&amp;gt;&lt;/code&gt;&lt;br&gt;
This will create a file inside our main folder. For this case let's call our file &lt;em&gt;main.py&lt;/em&gt; At this point, you can run certain commands like:&lt;br&gt;
&lt;code&gt;git status&lt;/code&gt;&lt;br&gt;
which allows us to see files that we have not started to track, files we have modified, files we have staged, files we have modified after staging, and so on. Files that are not tracked means that they will not be pushed to Github once we get to that.&lt;/p&gt;

&lt;p&gt;We can now write a simple sentence on our terminal using a command called &lt;em&gt;echo&lt;/em&gt; as follows:&lt;br&gt;
&lt;code&gt;echo "print('This is a new file')" &amp;gt; main.py&lt;/code&gt;&lt;br&gt;
The echo command prints text, but when used together with the greater than sign (&lt;em&gt;&amp;gt;&lt;/em&gt;) and the file name, will write the text into the file specified. At this point, we are on our working directory. Git does not know what it needs to stage. So how do we stage files?&lt;/p&gt;
&lt;h3&gt;
  
  
  Staging a File(s)
&lt;/h3&gt;

&lt;p&gt;Staging a file basically tells Git that we want to commit our changes that we have made so far. Moreover, it will also stage any new, modified, or deleted paths too. We can do this by basically staging everything or staging a single file, or staging specific files.&lt;br&gt;
To do so, we can do the following&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git add &lt;span class="nb"&gt;.&lt;/span&gt; // Stages everything that is yet to be tracked.
git add &amp;lt;filename&amp;gt; // Stages a single file.
git add &amp;lt;filename_1&amp;gt; &amp;lt;filename_2&amp;gt; ... // Stages specific files.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;At this point, we are in the staging area. We know what we want to commit/update in our remote repository. In the next stage, we will commit the staged files.&lt;/p&gt;

&lt;h3&gt;
  
  
  Committing a File(s)
&lt;/h3&gt;

&lt;p&gt;We now commit our changes so Git records a snapshot of what we have done. This is important, as git uses these commits to help the user go back to a certain point in your branch.&lt;br&gt;
To create a commit, We use this command:&lt;br&gt;
&lt;code&gt;git commit -m "Add main Python file"&lt;/code&gt;&lt;br&gt;
The commit message should be in double quotes. Once this is done, we need to to point our local folder to our remote repository. If not created, you will need to create a repository.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Note&lt;/em&gt;: At this stage of our workflow, we are now in the local repository. We have a full committed history of what we have done, but it is local. We are yet to update on our remote repository.&lt;/p&gt;

&lt;h3&gt;
  
  
  Link Our Local Repository to Remote Repository
&lt;/h3&gt;

&lt;p&gt;We will first create a repository on Github. To do this, simply navigate to your Github account on your browser and click &lt;em&gt;New Repository&lt;/em&gt; button on your Repositories page. You will then provide a name for your repository, provide a description, and you can later have it as Private or Public of other users to access it. Once that is done, you can click the &lt;em&gt;Create repository&lt;/em&gt; button. For this case, our repository is called &lt;em&gt;health_records_analysis&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;This has now created our repository. This repository contains a link which we can share to other users, and this is the link that we need to link our local folder with the newly created repository. To do this, simply access it once you scroll down in the page you are in the simply copy the http link. This is what we shall use. The link usually looks like this &lt;em&gt;&lt;a href="http://github.com/" rel="noopener noreferrer"&gt;http://github.com/&lt;/a&gt;/&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;We will then go back to the terminal we were in and enter the following command&lt;br&gt;
&lt;code&gt;git remote add origin &amp;lt;repository_link&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Great! We can now conduct the final step, &lt;em&gt;pushing&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Pushing Our Changes To Github
&lt;/h3&gt;

&lt;p&gt;To push to Github, we only need a single command:&lt;br&gt;
&lt;code&gt;git push -u origin main&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;git push&lt;/em&gt; will send our local commit to the remote repository&lt;br&gt;
&lt;em&gt;origin&lt;/em&gt; basically is the name of our remote repository&lt;br&gt;
&lt;em&gt;main&lt;/em&gt; is the branch we are pushing to&lt;br&gt;
&lt;em&gt;-u&lt;/em&gt; will establish origin/main as the remote branch.&lt;/p&gt;

&lt;p&gt;You can confirm this by going back to your Github account and refresh. You will see the file we just pushed, and the commit message. As you may have guessed, this is the remote repository. This is now where we have pushed our changes, and all this can be shared to relevant users.&lt;/p&gt;

&lt;h2&gt;
  
  
  Closing
&lt;/h2&gt;

&lt;p&gt;Learning Git is important as a person working with any kind of projects that require proper tracking, can be collaborative, and even makes your work neat. It is a skill that is important, and one that I, personally has had fun learning, and look forward to sharing my progress.&lt;/p&gt;

</description>
      <category>github</category>
      <category>git</category>
    </item>
  </channel>
</rss>
