<?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>Forem: João Ricardo Mattedi Cetto</title>
    <description>The latest articles on Forem by João Ricardo Mattedi Cetto (@joaomcetto).</description>
    <link>https://forem.com/joaomcetto</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%2F2087601%2F41b60646-c195-4598-9dcd-cad33b8c4341.jpg</url>
      <title>Forem: João Ricardo Mattedi Cetto</title>
      <link>https://forem.com/joaomcetto</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/joaomcetto"/>
    <language>en</language>
    <item>
      <title>How to use Git Stash</title>
      <dc:creator>João Ricardo Mattedi Cetto</dc:creator>
      <pubDate>Thu, 19 Sep 2024 14:36:23 +0000</pubDate>
      <link>https://forem.com/ledsifes/how-to-use-git-stash-1dgj</link>
      <guid>https://forem.com/ledsifes/how-to-use-git-stash-1dgj</guid>
      <description>&lt;p&gt;While you work on a project in Git, you may encounter situations where you need to temporarily set aside your current work to switch branches or handle other tasks. In these cases, committing the changes of an uncompleted work isn’t always ideal. This is where the command “git stash” becomes useful. With this feature, you can save your uncommitted changes and clean up your workspace, it allows you to return to them later without losing progress. In this post, we’ll explore how to effectively use this feature and some key commands to manage your stashes.&lt;/p&gt;

&lt;h2&gt;
  
  
  STASH
&lt;/h2&gt;

&lt;p&gt;In Git, the git stash command allows you to temporarily save changes made in your working directory without committing them. This is particularly useful when you’re working on a project but need to switch branches or handle another task without losing your uncommitted changes, which may not yet be ready to commit.&lt;/p&gt;

&lt;h2&gt;
  
  
  How does &lt;code&gt;git stash&lt;/code&gt; work?
&lt;/h2&gt;

&lt;p&gt;When you use &lt;code&gt;git stash&lt;/code&gt;, it stores changes from both the working directory and the index (staging area), cleaning up your workspace and allowing you to switch focus to another part of the project. These changes are saved in a "stash stack," which allows you to retrieve them later when you’re ready to continue.&lt;/p&gt;

&lt;h2&gt;
  
  
  Basic Commands
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;git stash&lt;/code&gt;: Saves uncommitted changes in a temporary stash and cleans up  the working directory.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;git stash apply&lt;/code&gt;: Reapplies the stashed changes without removing them - from the stash stack.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;git stash pop&lt;/code&gt;: Restores the stashed changes and removes them from the stash stack.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;git stash list&lt;/code&gt;: Lists all saved stashes.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;git stash drop [stash_id]&lt;/code&gt;: Removes a specific stash from the list.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;git stash clear&lt;/code&gt;: Removes all stashes from the stack.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Using stash
&lt;/h2&gt;

&lt;p&gt;Scenario:&lt;br&gt;
You're working on a new feature in your project, but a bug appears and you need to switch branches to fix it. You don't want to commit your incomplete work yet, but also don't want to lose your changes.&lt;/p&gt;
&lt;h2&gt;
  
  
  Steps to stash:
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;1.&lt;/strong&gt; Current Situation: You've made several changes to files while working on the feature-branch. Use the command &lt;code&gt;git add .&lt;/code&gt; to add your work in progress (WIP) to the stage and, with &lt;code&gt;git status&lt;/code&gt; you'll see that your WIP is in the stage.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ git status
On branch feature-branch
Changes to be committed:
  (use "git restore --staged &amp;lt;file&amp;gt;..." to unstage)
        modified:   teste/testando.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;2.&lt;/strong&gt; Save the Changes to temporarily save your work without committing it, use &lt;code&gt;git stash&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ git stash
Saved working directory and index state WIP on feature-branch: 7e9ca1a first commit
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;3.&lt;/strong&gt; Fix the bug on main, commit the changes, and push them.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4.&lt;/strong&gt; Return to Your Feature Branch once the bug fix is done with &lt;code&gt;git checkout feature-branch&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5.&lt;/strong&gt; Reapply Your Stashed Changes using &lt;code&gt;git stash pop&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ git stash pop
On branch feature-branch
Changes not staged for commit:
  (use "git add &amp;lt;file&amp;gt;..." to update what will be committed)
  (use "git restore &amp;lt;file&amp;gt;..." to discard changes in working directory)
        modified:   teste/testando.txt

no changes added to commit (use "git add" and/or "git commit -a")
Dropped refs/stash@{0} (8e60d99fc7d822c5c0c67b7c3f709d2085026eb2)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Obs:&lt;/strong&gt; This command applies your saved changes back to the working directory and removes them from the stash list.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Did you enjoy the post? If you’d like to explore more Git and GitHub features, check out: &lt;a href="https://dev.to/ledscolatina/forks-in-github-39l7"&gt;Forks in GitHub&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>git</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Forks in GitHub</title>
      <dc:creator>João Ricardo Mattedi Cetto</dc:creator>
      <pubDate>Thu, 19 Sep 2024 13:07:55 +0000</pubDate>
      <link>https://forem.com/ledsifes/forks-in-github-39l7</link>
      <guid>https://forem.com/ledsifes/forks-in-github-39l7</guid>
      <description>&lt;p&gt;In this post, I will introduce a important Git/GitHub feature: Forks &lt;/p&gt;

&lt;h2&gt;
  
  
  FORK
&lt;/h2&gt;

&lt;p&gt;A fork creates an exact copy of the original repository within the user’s profile, while maintaining a link to the source repository. The primary purpose of a fork is to allow users to modify the original project, experiment with new features, or contribute to the project without directly impacting the main repository.&lt;/p&gt;

&lt;h2&gt;
  
  
  MAIN USES OF FORK
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Collaboration in Open-Source Projects: Developers can contribute to projects without needing direct permission from the original repository;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Project Personalization: Users can make modifications to suit their specific needs while maintaining a separate repository.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  HOW TO MAKE A FORK?
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;1.&lt;/strong&gt; Navigate to the repository you wish to fork and click on the "Fork" option:&lt;br&gt;
&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7momjzlecv4999bd2jp7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7momjzlecv4999bd2jp7.png" width="800" height="161"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2.&lt;/strong&gt; Create your fork by selecting the repository:&lt;br&gt;
&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0z83cfcbe0fu5f63t8et.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0z83cfcbe0fu5f63t8et.png" width="737" height="562"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3.&lt;/strong&gt; Copy the clone link of your forked repository to your local machine. You can then make changes or implement new features:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpqycd2j7vzhzfnz2gjyn.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpqycd2j7vzhzfnz2gjyn.png" width="800" height="417"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4.&lt;/strong&gt; Clone the repository in your IDE and begin coding!!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ git clone https://github.com/JoaoRicardoCetto/RNA-Evolutiva-C-.git
Cloning into 'RNA-Evolutiva-C-'...
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0 (from 0)
Receiving objects: 100% (3/3), 4.74 KiB | 4.74 MiB/s, done.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;5.&lt;/strong&gt; Enter the local repository, open the folder in your IDE, make your modifications, add them to the stage, commit and push it to make a pull request.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ git commit -am "adding to the stage and committing"
warning: in the working copy of '.vscode/settings.json', LF will be replaced by CRLF the next time Git touches it
[main eedc221] adding to the stage and committing
 1 file changed, 1 insertion(+), 1 deletion(-)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;6.&lt;/strong&gt; Once you have made your changes and committed them, you can create a pull request to the main repository, suggesting your modifications to be merged into the original project.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;OBS:&lt;/strong&gt; To incorporate commits and updates from the upstream repository into your fork, use the following command: &lt;code&gt;git pull upstream main&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;This command fetches the latest changes from the upstream repository’s main branch and merges them into your local fork. Make sure you've previously set up the upstream repository with the correct URL: &lt;br&gt;
&lt;code&gt;git remote add upstream https://github.com/Owner-Name/Repository-You-Forked&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This ensures that your fork stays in sync with the original project.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Did you enjoy the post? If you’d like to explore more Git and GitHub features, check out: &lt;a href="https://dev.to/ledscolatina/how-to-use-git-stash-1dgj"&gt;How to use Git Stash&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

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