<?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: Vishnu Prasaath</title>
    <description>The latest articles on DEV Community by Vishnu Prasaath (@pvishnuprasaath).</description>
    <link>https://dev.to/pvishnuprasaath</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%2F1053255%2Ff9f60eae-79b5-4533-8b6d-b2d27fbb9de9.png</url>
      <title>DEV Community: Vishnu Prasaath</title>
      <link>https://dev.to/pvishnuprasaath</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/pvishnuprasaath"/>
    <language>en</language>
    <item>
      <title>Blockchain: Understanding basics - part 2</title>
      <dc:creator>Vishnu Prasaath</dc:creator>
      <pubDate>Sun, 28 May 2023 05:58:51 +0000</pubDate>
      <link>https://dev.to/pvishnuprasaath/blockchain-understanding-basics-part-2-od5</link>
      <guid>https://dev.to/pvishnuprasaath/blockchain-understanding-basics-part-2-od5</guid>
      <description>&lt;p&gt;With peer-to-peer models, even if all peers are trusted, there is a potential problem of agreement or consensus let's assume that each peer is updating at a different speed and end up holding different states, how to determine the real or true state of the data?&lt;/p&gt;

&lt;p&gt;In the case of an untrusted peer-to-peer network, we cant necessarily trust any of the peers, how to ensure that the bad peers won't corrupt the system?&lt;/p&gt;




&lt;h3&gt;
  
  
  CONSENSUS: &lt;em&gt;How to resolve conflicts?&lt;/em&gt;
&lt;/h3&gt;

&lt;p&gt;A very basic conflict is when multiple miners create blocks at the same time. As the blocks take time to be shared across the network, which one should be considered a legit block?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example:&lt;/strong&gt; Lets consider that all the nodes on the network have synchronised their blockchains, and they are all on block number 80.&lt;br&gt;&lt;br&gt;
If three different miners create Block 81 at roughly the same time, which Block 81 should be considered valid? Remember that each Block 81 will look slightly different: They will certainly contain a different payment address for the 25 BTC block reward, and they may contain a different set of transactions. Lets call them 81a, 81b, 81c.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--vUHDGV_I--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://i0.wp.com/bitsonblocks.net/wp-content/uploads/2015/09/three_blocks1.jpg%3Fresize%3D420%252C182%26ssl%3D1" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--vUHDGV_I--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://i0.wp.com/bitsonblocks.net/wp-content/uploads/2015/09/three_blocks1.jpg%3Fresize%3D420%252C182%26ssl%3D1" alt="three_blocks" width="420" height="182"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Which block will be considered the legit one?&lt;br&gt;&lt;br&gt;
How to resolve this?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Longest chain rule.&lt;/strong&gt; In Bitcoin, this conflict is resolved by a rule called the longest chain rule.&lt;/p&gt;

&lt;p&gt;In the example above, you would assume that the first Block 81 you see is valid. Lets say you see 81a first. You can start building the next block on that, trying to create 82a:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--qr6OlAfb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://i0.wp.com/bitsonblocks.net/wp-content/uploads/2015/09/mine_on_first.jpg%3Fresize%3D484%252C154%26ssl%3D1" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--qr6OlAfb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://i0.wp.com/bitsonblocks.net/wp-content/uploads/2015/09/mine_on_first.jpg%3Fresize%3D484%252C154%26ssl%3D1" alt="mine_on_first" width="484" height="154"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Treat the first block you see as legitimate.&lt;/p&gt;

&lt;p&gt;However, in a few seconds, you may see 81b. If you see this, you keep an eye on it. If later you see 82b, the longest chain rule says that you should regard the longer b chain as the valid one (80, 81b, 82b) and ignore the shorter chain (80, 81a). So you stop trying to make 82a and instead, start trying to make 83b:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--M5MWDszg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://i0.wp.com/bitsonblocks.net/wp-content/uploads/2015/09/mine_on_longest.jpg%3Fresize%3D563%252C232%26ssl%3D1" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--M5MWDszg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://i0.wp.com/bitsonblocks.net/wp-content/uploads/2015/09/mine_on_longest.jpg%3Fresize%3D563%252C232%26ssl%3D1" alt="mine_on_longest" width="563" height="232"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Longest chain rule: If there are multiple blocks, treat the longest chain as legitimate.&lt;/p&gt;

&lt;p&gt;The longest chain rule is the rule that the Bitcoin blockchain ecosystem uses to resolve these conflicts which are common in distributed networks.&lt;/p&gt;

&lt;p&gt;However, with a more centralised or trusted blockchain network, we can make decisions by using a trusted, or senior validator to arbitrate in these cases.&lt;/p&gt;




&lt;h3&gt;
  
  
  DEFENCE: &lt;em&gt;How do you make it hard for baddies?&lt;/em&gt;
&lt;/h3&gt;

&lt;p&gt;The most common issue with permissionless, or open networks is that they can be attacked easily. So we need to make sure the network as a whole needs to be trustworthy, even if few nodes aren't.&lt;/p&gt;

&lt;p&gt;Understanding the Miscreant's Capabilities&lt;/p&gt;

&lt;p&gt;A dishonest miner, despite causing concern, is confined in terms of the harm they can inflict. Here are some actions a dishonest miner can take:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Refusal to relay valid transactions: A dishonest miner can choose not to pass valid transactions to other nodes within the network.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Manipulating block contents: They can attempt to create blocks that selectively include or exclude specific transactions according to their preferences.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Attempting to construct a longer chain: By creating a sequence of blocks that surpasses the existing main chain, a dishonest miner can render previously accepted blocks as "orphans," thereby excluding them from the primary chain.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;However, a dishonest miner is unable to execute the following actions:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Generating bitcoins out of thin air: While theoretically possible, creating bitcoins out of nothing remains unfeasible. If such transactions are attempted, other nodes will reject them, emphasizing the importance of confirming transactions across multiple nodes.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Stealing bitcoins from your account: The security measures in place prevent a dishonest miner from pilfering bitcoins from a user's account.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Impersonation or unauthorized payments: A dishonest miner cannot conduct payments on behalf of others or pretend to be someone else within the network.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Transaction Security&lt;/p&gt;

&lt;p&gt;The impact of a dishonest miner's actions on transactions is limited, primarily due to the presence of honest nodes in the network. If the majority of nodes are honest, they will reject any invalid transactions introduced by the miscreant. Moreover, these honest nodes will propagate valid transactions to ensure their inclusion in subsequent blocks, even if the dishonest miner refuses to relay them.&lt;/p&gt;

&lt;p&gt;Block Security&lt;/p&gt;

&lt;p&gt;In the context of blocks, the influence of a miscreant with significant block creation power becomes more pronounced. They can delay a specific transaction by omitting it from their blocks. However, other honest nodes will recognize this transaction as an "unconfirmed transaction" and incorporate it into their blocks.&lt;/p&gt;

&lt;p&gt;A more significant concern arises when a dishonest miner manages to construct a longer chain of blocks compared to the rest of the network. By invoking the "longest chain rule," the miscreant can effectively undermine a transaction. Here's an overview of this strategy:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Creating dual payments: Initiate two payments with the same bitcoinsone to an online retailer and the other to another address under your control.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Broadcasting the retailer payment: Only share the payment intended for the retailer with the network.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Retailer payment confirmation: As the payment is included in an honest block, the retailer dispatches the ordered goods.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Secretly constructing a longer chain: Covertly generates a longer chain of blocks that excludes the payment to the retailer but includes the payment to yourself.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Publishing the longer chain: When the longer chain is published, nodes following the "longest chain rule" ignore the honest block containing the retailer payment. Instead, they continue building on the longer chain, effectively orphaning the honest block.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Invalidating the retailer payment: Due to the existence of the longer chain, honest nodes deem the original payment to the retailer invalid, as the bitcoins associated with it have already been spent according to your longer chain.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--TYcGsS38--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://i0.wp.com/bitsonblocks.net/wp-content/uploads/2015/09/double_spend1.jpg%3Fresize%3D558%252C630%26ssl%3D1" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--TYcGsS38--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://i0.wp.com/bitsonblocks.net/wp-content/uploads/2015/09/double_spend1.jpg%3Fresize%3D558%252C630%26ssl%3D1" alt="double_spend" width="558" height="630"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;double spend&lt;/strong&gt; attack.&lt;/p&gt;

&lt;p&gt;This is called a double spend because the same bitcoins were spent twice but the second one was the one that became part of the eventual blockchain, and the first one eventually gets rejected.&lt;/p&gt;

&lt;p&gt;How to make it hard for dishonest miners to create blocks?&lt;/p&gt;

&lt;p&gt;Remember, this is only a problem for ledgers where block-makers arent trusted.&lt;/p&gt;

&lt;p&gt;Essentially you want to make it hard, or expensive for baddies to add blocks. In Bitcoin, this is done by making it &lt;strong&gt;computationally expensive&lt;/strong&gt; to add blocks. Computationally expensive means takes a lot of computer processing power and translates to financially expensive (as computers need to be bought then run and maintained).&lt;/p&gt;

&lt;p&gt;The computation itself is a &lt;strong&gt;guessing game&lt;/strong&gt; where block-makers need to guess a number, which when crunched with the rest of the block data contents, results in a hash/fingerprint that is smaller than a certain number. That number is related to the difficulty of mining which is related to the total network processing power. The more computers join in to process blocks, the harder it gets, in a self-regulating cycle.&lt;/p&gt;

&lt;p&gt;Every 2,016 blocks (roughly every 2 weeks), the Bitcoin network adjusts the difficulty of the guessing game based on the speed in which the blocks have been created.&lt;/p&gt;

&lt;p&gt;This guessing game is called &lt;strong&gt;Proof of work&lt;/strong&gt;. By publishing the block with a fingerprint that is smaller than the target number, you are proving that you did enough guesswork to satisfy the network at that point in time.&lt;/p&gt;

</description>
      <category>blockchain</category>
      <category>bitcoin</category>
      <category>ethereum</category>
      <category>web3</category>
    </item>
    <item>
      <title>Blockchain: Understanding basics - part 1</title>
      <dc:creator>Vishnu Prasaath</dc:creator>
      <pubDate>Thu, 27 Apr 2023 13:05:31 +0000</pubDate>
      <link>https://dev.to/pvishnuprasaath/blockchain-understanding-basics-5hda</link>
      <guid>https://dev.to/pvishnuprasaath/blockchain-understanding-basics-5hda</guid>
      <description>&lt;p&gt;In this article let's try to demystify and understand the basics of the blockchain infrastructure and see how it contributes to the &lt;strong&gt;web3&lt;/strong&gt; ecosystem.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;What is a blockchain?&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Basically &lt;strong&gt;, blockchain is a Data Structure&lt;/strong&gt;. Very similar to other data structures like databases (rows, columns, tables), text files, CSV, images, lists, and so on. Blockchain competes most closely with a database.&lt;/p&gt;

&lt;p&gt;For an analogy, let's visualize blockchain &lt;em&gt;as&lt;/em&gt; pages in a book&lt;br&gt;&lt;br&gt;
&lt;strong&gt;Chain = Book&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
&lt;strong&gt;Block = Page&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
&lt;strong&gt;Blocks in Chain = Pages in Book&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
Each page in a book contains:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;text&lt;/strong&gt; : content/story&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;information about the page&lt;/strong&gt; : chapter number/title, page number&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Similarly in a blockchain block, each block has:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;contents&lt;/strong&gt; of the block: Transaction details in cryptocurrency, or any data which we prefer to store&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;header&lt;/strong&gt; : &lt;strong&gt;Metadata&lt;/strong&gt; - data about the block. Some sort of technical info about the block, a reference to the previous block, and a fingerprint (hash) of the data for the current block&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In blockchains, each block references the previous block by a computed hash value called the &lt;strong&gt;blocks fingerprint&lt;/strong&gt;. The fingerprint is computed based on the &lt;strong&gt;contents&lt;/strong&gt; of the block.&lt;/p&gt;

&lt;p&gt;The concept of maintaining a reference to the previous blocks can be visualized as a &lt;strong&gt;linked list structure&lt;/strong&gt;. In the linked list each node holds a reference to the next node, whereas in the blockchain each block holds a reference to the previous block.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--JR21rrCw--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://i0.wp.com/bitsonblocks.net/wp-content/uploads/2015/09/books_and_blocks.png%3Fresize%3D570%252C129%26ssl%3D1" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--JR21rrCw--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://i0.wp.com/bitsonblocks.net/wp-content/uploads/2015/09/books_and_blocks.png%3Fresize%3D570%252C129%26ssl%3D1" alt="books_and_blocks" width="570" height="129"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This creates the fancy structure called the &lt;strong&gt;blockchain&lt;/strong&gt;!&lt;/p&gt;




&lt;p&gt;The fingerprint in each block is responsible for taking care of the consistency and validity of the data. If someone tries to meddle with any of the data, they have to end up regenerating all the fingerprints from that point forwards and the blockchain will look different. This is basically impossible as the process of creating fingerprints is difficult and slow. Therefore, if someone wants to re-write parts of the blockchain, it will take them a long time, and they have to catch up with and overtake the rest of the honest network. Which is not feasible.&lt;/p&gt;

&lt;p&gt;Hence the blockchain is called &lt;strong&gt;immutable&lt;/strong&gt; (as it cannot be changed).&lt;/p&gt;

&lt;p&gt;The below image shows the inside of a blockchain block: the fingerprints are unique to the blocks contents.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--rhDOt_Xe--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn.hashnode.com/res/hashnode/image/upload/v1682595755311/91e67114-6349-4083-ae30-9c2de7184735.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--rhDOt_Xe--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn.hashnode.com/res/hashnode/image/upload/v1682595755311/91e67114-6349-4083-ae30-9c2de7184735.png" alt="block-chain-inside" width="800" height="224"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h3&gt;
  
  
  Data Distribution
&lt;/h3&gt;

&lt;p&gt;There are two ways of distributing data in a network: Client-Server and Peer to peer. Blockchain is built on top of the &lt;strong&gt;peer-to-peer&lt;/strong&gt; model.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--zXdliB7t--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn.hashnode.com/res/hashnode/image/upload/v1682592527479/b730f1ac-9e8b-4fa8-8c28-cdb8cc47c980.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--zXdliB7t--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn.hashnode.com/res/hashnode/image/upload/v1682592527479/b730f1ac-9e8b-4fa8-8c28-cdb8cc47c980.png" alt="peer-to-peer and client-server" width="800" height="339"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Client-server&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
This is a traditional approach where the server holds 100% of the data, and the clients connect via required protocols to access/consume the data.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Peer-to-peer&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
In peer-to-peer models, each peer has 100% of the data (or as close to it as possible), and updates are shared around. This is less efficient than client-server, as data is replicated many times. However, it's more robust as there is no central server that can be controlled, so closing down peer-to-peer networks is harder.&lt;/p&gt;

&lt;p&gt;But on the contrary, the peer-to-peer model comes with its downsides. In the real world each peer on the network is gonna process and update at its own speed and latency and end up having varied states at a given timestamp. Deciding on which peer holds the valid data and which peer has stale or tampered data is ambiguous.&lt;/p&gt;

&lt;p&gt;This conflict is resolved by a rule called the &lt;strong&gt;longest chain rule&lt;/strong&gt; - If you see multiple blocks, treat the longest chain as legitimate. We can discuss in-depth on this conflict resolution and consensus in a separate article.&lt;br&gt;
&lt;a href="https://dev.to/pvishnuprasaath/blockchain-understanding-basics-part-2-od5"&gt;blockchain-understanding-basics-part-2&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Blockchain is not something that is associated with only &lt;strong&gt;Bitcoin&lt;/strong&gt;. &lt;strong&gt;Ethereum&lt;/strong&gt; is a great variant of blockchain with &lt;strong&gt;smart contracts&lt;/strong&gt;. There are significant challenges involved.&lt;br&gt;&lt;br&gt;
On the other hand, private or internally distributed ledgers and blockchains can be deployed to solve a wide range of problems and use cases.&lt;/p&gt;

</description>
      <category>blockchain</category>
      <category>bitcoin</category>
      <category>ethereum</category>
      <category>web3</category>
    </item>
    <item>
      <title>GitHub CLI: gives wings to terminal</title>
      <dc:creator>Vishnu Prasaath</dc:creator>
      <pubDate>Thu, 13 Apr 2023 16:54:09 +0000</pubDate>
      <link>https://dev.to/pvishnuprasaath/github-cli-gives-wings-to-terminal-1ic</link>
      <guid>https://dev.to/pvishnuprasaath/github-cli-gives-wings-to-terminal-1ic</guid>
      <description>&lt;p&gt;When working with git, youre obviously aware that you need to switch to the web browser to perform various actions on the GitHub repo - Pull Request, Issues, Review... The GitHub CLI tool gives wings to the cmd-line, so you can execute many of these actions without leaving the cmd-line.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Setup&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;To get started, visit the &lt;a href="https://cli.github.com/manual/installation" rel="noopener noreferrer"&gt;&lt;strong&gt;installation page&lt;/strong&gt;&lt;/a&gt; and find instructions on how to install GitHub CLI for your preferred OS. The easy-peasy way for Windows users is to use &lt;a href="https://scoop.sh/" rel="noopener noreferrer"&gt;&lt;strong&gt;scoop&lt;/strong&gt;&lt;/a&gt; package manager.&lt;/p&gt;

&lt;p&gt;Below are snapshots of install instructions for each supported platform:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Windows:&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;macOS:&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Debian/Ubuntu Linux:&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Authenticate GitHub CLI
&lt;/h2&gt;

&lt;p&gt;Authenticate CLI to access your GitHub account.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;gh auth login

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1681376462925%2Fec752011-11bd-4370-983f-761c9e3dfaaa.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%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1681376462925%2Fec752011-11bd-4370-983f-761c9e3dfaaa.png" alt="img1"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Select &lt;code&gt;Login with a Web browser&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;$ gh auth login
? What account do you want to log into? GitHub.com
? What is your preferred protocol for Git operations? HTTPS
? Authenticate Git with your GitHub credentials? Yes
? How would you like to authenticate GitHub CLI? Login with a web browser

! First copy your one-time code: 1DD9-7BD3
Press Enter to open github.com in your browser... 
 Authentication complete.
- gh config set -h github.com git_protocol https
 Configured git protocol
 Logged in as pvishnuprasaath

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1681376809577%2Fa6f4dc62-bda2-41bd-8993-8b24475def8e.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%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1681376809577%2Fa6f4dc62-bda2-41bd-8993-8b24475def8e.png" alt="img2"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;GitHub CLI Command Struct&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;gh&lt;/code&gt; command is structured like a tree for grabbing easily. There are basically two levels of commands. The first level consists of the below commands:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;auth&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;browse&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;issue&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;pr&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;release&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;repo&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;codespace&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;gist&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Each command has a second level of command where you specify the operation to perform such as &lt;code&gt;gh pr create&lt;/code&gt; or &lt;code&gt;gh repo view&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Let's dive deep into the most commonly used commands.&lt;/p&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;GitHub Repo Command&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Cloning a repo with the &lt;code&gt;gh&lt;/code&gt; command is easier than using the &lt;code&gt;git&lt;/code&gt; command. You no longer need to type or copy-paste the long Git URL to clone&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;gh repo clone OWNER/REPO
gh repo clone mui/material-ui

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can also fork existing repositories to your account easily from the command line.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;gh repo fork cli/cli

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To view the description and README of a project hosted on GitHub use the &lt;code&gt;gh repo view&lt;/code&gt; command.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;gh repo view facebook/react

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's create a new GitHub repository from the command line. First, we need to create a new project.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ npx create-next-app sample-app
$ cd sample-app

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To create a repo from the command line, just run the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ gh repo create --public
 Created repository pvishnuprasaath/sample-app on GitHub
 Added remote https://github.com/pvishnuprasaath/sample-app.git

# Push your project code to your new remote repository
$ git push -u origin main

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  &lt;strong&gt;Pull Request Command&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;If you know classic &lt;strong&gt;git flow&lt;/strong&gt; , creating PR is quite an effort. GitHub CLI makes it easy to create PR directly from your terminal. After a &lt;code&gt;git commit&lt;/code&gt;, you can execute &lt;code&gt;gh pr create&lt;/code&gt;. It will prompt a couple of inputs. Post that, the PR link is displayed in the terminal.&lt;/p&gt;

&lt;p&gt;Heres the full output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ gh pr create
Creating pull request for feature-1 into master in pvishnuprasaath/sample-app
? Title Added new feature
? Body Implemented and testted new feature for ABC
? What is next? Submit
Enumerating objects: 6, done.
Counting objects: 100% (6/6), done.
Delta compression using up to 8 threads
Compressing objects: 100% (4/4), done.
Writing objects: 100% (4/4), 328 bytes | 328.00 KiB/s, done.
Total 4 (delta 2), reused 0 (delta 0), pack-reused 0
remote: Resolving deltas: 100% (2/2), completed with 2 local objects.
remote:
remote: Create a pull request for 'feature-1' on GitHub by visiting:
remote: https://github.com/pvishnuprasaath/sample-app/pull/new/feature-1
remote:
To https://github.com/pvishnuprasaath/sample-app.git
* [new branch] HEAD -&amp;gt; feature-1
Branch 'feature-1' set up to track
remote branch 'feature-1' from 'origin'.
https://github.com/pvishnuprasaath/sample-app/pull/3

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A short version:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;gh pr create --title "PR title" --body "PR body"

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To view all the pull requests in the current repo, run &lt;code&gt;gh pr list&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;$ gh pr list
Showing 1 of 1 pull request in pvishnuprasaath/sample-app
#3 Added new feature feature-1

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Use the command &lt;code&gt;gh pr checkout &amp;lt;number&amp;gt;&lt;/code&gt; to checkout a PR. This command will pull the remote feature branch and switch to it. &lt;code&gt;gh pr diff&lt;/code&gt; will show the delta for the current PR.&lt;/p&gt;

&lt;p&gt;Lets take a look at the &lt;code&gt;gh pr merge&lt;/code&gt; command. As youre probably aware, GitHub checks for vulnerabilities in your code and provides solutions via bump pull requests. Heres an example:&lt;/p&gt;

&lt;p&gt;Merging multiple PRs one by one is a tiring process. &lt;code&gt;gh pr merge&lt;/code&gt; makes it easy to merge a particular PR directly from the terminal.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ gh pr merge 4
? What merge method would you like to use? Create a merge commit
remote: Counting objects: 100% (1/1), done.
remote: Counting objects: 100% (1/1), done.
remote: Total 1 (delta 0), reused 0 (delta 0), pack-reused 0        
Unpacking objects: 100% (1/1), 624 bytes | 89.00 KiB/s, done.       
From https://github.com/pvishnuprasaath/sample-app   
 * branch main -&amp;gt; FETCH_HEAD
   09f8c52..7a8a3f2 main -&amp;gt; origin/main
Updating 09f8c52..7a8a3f2
Fast-forward
 src/data/data.ts | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
 Deleted branch FixLink and switched to branch main

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Additional &lt;code&gt;gh pr&lt;/code&gt; commands&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://cli.github.com/manual/gh_pr_view" rel="noopener noreferrer"&gt;&lt;code&gt;gh pr view&lt;/code&gt;&lt;/a&gt;: displays the title, body, and other information about a pull request.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://cli.github.com/manual/gh_pr_status" rel="noopener noreferrer"&gt;&lt;code&gt;gh pr status&lt;/code&gt;&lt;/a&gt;: show the status of relevant pull requests.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://cli.github.com/manual/gh_pr_ready" rel="noopener noreferrer"&gt;&lt;code&gt;gh pr ready&lt;/code&gt;&lt;/a&gt;: make a pull request as ready for review.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://cli.github.com/manual/gh_pr_review" rel="noopener noreferrer"&gt;&lt;code&gt;gh pr review&lt;/code&gt;&lt;/a&gt;: add a review to a pull request.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://cli.github.com/manual/gh_pr_close" rel="noopener noreferrer"&gt;&lt;code&gt;gh pr close&lt;/code&gt;&lt;/a&gt;: close a pull request.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://cli.github.com/manual/gh_pr_reopen" rel="noopener noreferrer"&gt;&lt;code&gt;gh pr reopen&lt;/code&gt;&lt;/a&gt;: reopen a pull request.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;By now, there isn't a way to revert PR from the GitHub CLI yet :(&lt;/p&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;Issue Command&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://guides.github.com/features/issues/" rel="noopener noreferrer"&gt;&lt;strong&gt;Issues&lt;/strong&gt;&lt;/a&gt; are used to keep track of bugs, tasks and feature requests associated with a GitHub project repo. The command &lt;code&gt;gh issue create&lt;/code&gt; is used to create a new issue via the terminal:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ gh issue create
Creating issue in pvishnuprasaath/sample-app
? Title Fix Docker skill link

? Title Fix Docker skill link
? Body &amp;lt;Received&amp;gt;
? What's next? Submit
https://github.com/pvishnuprasaath/sample-app/issues/6

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;gh issue list&lt;/code&gt; command lists all issues in the current repo.&lt;/p&gt;

&lt;p&gt;The rest of &lt;code&gt;gh issue&lt;/code&gt; commands are quite similar to &lt;code&gt;gh pr&lt;/code&gt; commands. Below is a quick summary:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://cli.github.com/manual/gh_issue_view" rel="noopener noreferrer"&gt;&lt;code&gt;gh issue view&lt;/code&gt;&lt;/a&gt;: displays the title, body, and other information about an issue.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://cli.github.com/manual/gh_issue_status" rel="noopener noreferrer"&gt;&lt;code&gt;gh issue status&lt;/code&gt;&lt;/a&gt;: show the status of relevant issues.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://cli.github.com/manual/gh_issue_close" rel="noopener noreferrer"&gt;&lt;code&gt;gh issue close&lt;/code&gt;&lt;/a&gt;: close an issue.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://cli.github.com/manual/gh_issue_reopen" rel="noopener noreferrer"&gt;&lt;code&gt;gh issue reopen&lt;/code&gt;&lt;/a&gt;: reopen an issue.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  GitHub CLI Cheat Sheet
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Creating, deleting and configuring repo&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;gh repo create

gh repo create &amp;lt;name_of_repo&amp;gt; --public

gh repo create my-project --private --source=. --remote=upstream

gh repo edit --visibility &amp;lt;visibility-string&amp;gt;

gh repo sync

gh repo create --disable-issues=true --public

gh repo list

gh repo delete &amp;lt;name_of_repo&amp;gt;

gh repo clone &amp;lt;name_of_repo&amp;gt;

gh repo fork &amp;lt;name_of_repo&amp;gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To easily save a piece of code online use Gist:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Creating a gist&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;touch index.js // after create content for it

gh gist create index.js --public

gh gist create -

gh gist edit &amp;lt;gist_id&amp;gt; 

gh gist list --public 

gh gist list --secret

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Handling issues&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;gh issue create

gh issue list

gh issue status

git issue close &amp;lt;#number_issue&amp;gt;

gh list -A "&amp;lt;name_issue&amp;gt;"

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Handling Pull requests&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;gh pr create 

gh pr checkout &amp;lt;name&amp;gt;

gh pr diff &amp;lt;#number_of_pr&amp;gt;

gh review -c -b "nice work"

gh pr close &amp;lt;#number_of_pr&amp;gt; -d

gh pr reopen &amp;lt;#number_of_pr&amp;gt;

gh pr status

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;gh&lt;/code&gt; for sure saves up time in devflow. Gives additional hands to your terminal for managing the repository. Refer to the &lt;a href="https://cli.github.com/manual/" rel="noopener noreferrer"&gt;&lt;strong&gt;official docs&lt;/strong&gt;&lt;/a&gt; for new features and detailed info on using the existing commands.&lt;/p&gt;

</description>
      <category>git</category>
      <category>github</category>
      <category>githubcli</category>
      <category>pullrequest</category>
    </item>
    <item>
      <title>GitHub Actions CI/CD for React app hosted in GitHub Pages</title>
      <dc:creator>Vishnu Prasaath</dc:creator>
      <pubDate>Wed, 12 Apr 2023 03:57:12 +0000</pubDate>
      <link>https://dev.to/pvishnuprasaath/github-actions-cicd-for-react-app-hosted-in-github-pages-3ah3</link>
      <guid>https://dev.to/pvishnuprasaath/github-actions-cicd-for-react-app-hosted-in-github-pages-3ah3</guid>
      <description>&lt;p&gt;Let's create a simple GitHub Actions workflow that I use on my projects with React.&lt;/p&gt;

&lt;p&gt;This workflow created on &lt;a href="https://github.com/features/actions"&gt;GitHub Actions&lt;/a&gt; will take care of automatically building and deploying the app on &lt;a href="https://pages.github.com/"&gt;GitHub Pages&lt;/a&gt;. Can add testing and linting if needed. We will be triggering this workflow on every push event on the &lt;strong&gt;main/master branch&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Consider going over my prev &lt;a href="https://dev.to/pvishnuprasaath/host-react-app-in-github-pages-35p9"&gt;blog-post&lt;/a&gt; on setting up your React app hosting on GitHub Pages.&lt;/p&gt;

&lt;h2&gt;
  
  
  Configure React App
&lt;/h2&gt;

&lt;p&gt;A tiny bit of configuration is required on the React app side.&lt;/p&gt;

&lt;p&gt;Add the below &lt;code&gt;homepage&lt;/code&gt; property to your &lt;code&gt;package.json&lt;/code&gt; file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;For free GitHub user site, add this: 
"homepage": "https://{username}.github.io"

If you own a domain, add this:
"homepage": "https://mydomainname.com"

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--52sDUlqf--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn.hashnode.com/res/hashnode/image/upload/v1681030015020/bc19bfff-fb70-457e-b0ff-6a0e5a2ab97d.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--52sDUlqf--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn.hashnode.com/res/hashnode/image/upload/v1681030015020/bc19bfff-fb70-457e-b0ff-6a0e5a2ab97d.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" alt="img1" width="390" height="138"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Add both &lt;strong&gt;predeploy&lt;/strong&gt; and &lt;strong&gt;deploy&lt;/strong&gt; property scripts to the &lt;code&gt;package.json&lt;/code&gt; as below&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"predeploy": "npm run build",
"deploy": "gh-pages -d build"

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--WOge-_ZW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn.hashnode.com/res/hashnode/image/upload/v1681030290187/7fb123aa-6a9a-4864-9b67-b36cba2bbbf1.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--WOge-_ZW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn.hashnode.com/res/hashnode/image/upload/v1681030290187/7fb123aa-6a9a-4864-9b67-b36cba2bbbf1.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" alt="img2" width="323" height="157"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  Getting Started with GitHub Actions WorkFlow
&lt;/h2&gt;

&lt;p&gt;First, create a &lt;code&gt;workflow.yml&lt;/code&gt; file inside &lt;code&gt;.github\workflows&lt;/code&gt; dir&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--N5XUb-jB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn.hashnode.com/res/hashnode/image/upload/v1681236230142/0966325b-62b7-495c-b6b6-dcc088fd1c48.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--N5XUb-jB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn.hashnode.com/res/hashnode/image/upload/v1681236230142/0966325b-62b7-495c-b6b6-dcc088fd1c48.png" alt="img3" width="246" height="249"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The complete workflow is as below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;name: Build and Deploy

on:
  push:
    branches: ["main"]

permissions:
  contents: write

jobs:
  build-deploy:
    runs-on: ubuntu-latest

    strategy:
      matrix:
        node-version: [18.x]

    steps:
    - name: Checkout
      uses: actions/checkout@v3
    - name: Use Node.js ${{ matrix.node-version }}
      uses: actions/setup-node@v3
      with:
        node-version: ${{ matrix.node-version }}
        cache: "npm"
    - name: Install Packages
      run: npm ci
    - name: Build
      run: npm run build
    #- name: Test
    # run: npm test
    - name: Deploy🚀
      uses: JamesIves/github-pages-deploy-action@v4
      with:
        branch: gh-pages
        folder: build

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's understand each field put up here.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;on&lt;/code&gt; section describes the &lt;strong&gt;events&lt;/strong&gt; which should trigger the job. In this workflow we want the jobs to be triggered whenever someone does a &lt;code&gt;push&lt;/code&gt; into the &lt;code&gt;main&lt;/code&gt; branch.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;on:
  push:
    branches: ["main"]

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Our job needs write access to modify files in the &lt;code&gt;gh-pages&lt;/code&gt; branch. The final build files are pushed into the gh-pages branch of your repo. Using GitHub Secrets can also help achieve the same result.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;permissions:
  contents: write

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's get into the interesting section of defining the actual &lt;strong&gt;job&lt;/strong&gt; to be executed. &lt;em&gt;build-deploy&lt;/em&gt; is the user-defined name for the job.&lt;/p&gt;

&lt;p&gt;We need to mention the type of &lt;strong&gt;runner&lt;/strong&gt; on which the job needs to be executed. Pick &lt;code&gt;ubuntu-latest&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;jobs:
  build-deploy:
    runs-on: ubuntu-latest

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When we want the same job to be executed on multiple variants of the node version, we can use the &lt;code&gt;strategy matrix&lt;/code&gt;. Here we will stick to just 1 node version.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;strategy:
  matrix:
    node-version: [18.x]

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The first step in any job is to &lt;strong&gt;checkout&lt;/strong&gt; the repo at that particular instance. This ensures we have the latest code base for the further process.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;- name: Checkout
  uses: actions/checkout@v3

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Set up &lt;strong&gt;Node.js&lt;/strong&gt; on the freshly brought-up runner. To optimize the workflow execution we can &lt;strong&gt;cache&lt;/strong&gt; the npm packages.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; - name: Use Node.js ${{ matrix.node-version }}
   uses: actions/setup-node@v3
   with:
     node-version: ${{ matrix.node-version }}
     cache: "npm"

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then we instruct the job to perform &lt;code&gt;npm ci&lt;/code&gt;, &lt;code&gt;npm run build&lt;/code&gt;, &lt;code&gt;npm test&lt;/code&gt;. This covers the &lt;strong&gt;Build&lt;/strong&gt; and &lt;strong&gt;Test&lt;/strong&gt; phase.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;- name: Install Packages
  run: npm ci
- name: Build
  run: npm run build
- name: Test
  run: npm test

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Finally, it's time to &lt;strong&gt;deploy&lt;/strong&gt; and give life to the app. We will use the popular &lt;code&gt;JamesIves/github-pages-deploy-action@v4&lt;/code&gt; action for deploying straight into the gh-pages. Specify the &lt;strong&gt;branch name&lt;/strong&gt; on where the built files will be pushed to. Also, mention the &lt;strong&gt;source dir&lt;/strong&gt; from where to find the built files. In our case, &lt;code&gt;npm run build&lt;/code&gt; will dump files into the &lt;code&gt;./build&lt;/code&gt; dir.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;- name: Deploy 🚀
  uses: JamesIves/github-pages-deploy-action@v4
  with:
    branch: gh-pages
    folder: build

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the &lt;strong&gt;Actions&lt;/strong&gt; tab, we can see the execution status and log.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Z836WyhB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn.hashnode.com/res/hashnode/image/upload/v1681271645127/d1988253-0749-41c4-a1e4-2a68cb25d8aa.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Z836WyhB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn.hashnode.com/res/hashnode/image/upload/v1681271645127/d1988253-0749-41c4-a1e4-2a68cb25d8aa.png" alt="" width="608" height="598"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  References
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://github.com/features/actions"&gt;https://github.com/features/actions&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://pages.github.com/"&gt;https://pages.github.com/&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://create-react-app.dev/docs/deployment#github-pages"&gt;https://create-react-app.dev/docs/deployment#github-pages&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://help.github.com/pt/actions/configuring-and-managing-workflows/caching-dependencies-to-speed-up-workflows"&gt;https://help.github.com/pt/actions/configuring-and-managing-workflows/caching-dependencies-to-speed-up-workflows&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://github.com/actions/cache"&gt;https://github.com/actions/cache&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>react</category>
      <category>cicd</category>
      <category>githubactions</category>
      <category>github</category>
    </item>
    <item>
      <title>Dockerize React app for dev and prod</title>
      <dc:creator>Vishnu Prasaath</dc:creator>
      <pubDate>Tue, 11 Apr 2023 04:59:51 +0000</pubDate>
      <link>https://dev.to/pvishnuprasaath/dockerize-react-app-for-dev-and-prod-3c84</link>
      <guid>https://dev.to/pvishnuprasaath/dockerize-react-app-for-dev-and-prod-3c84</guid>
      <description>&lt;p&gt;Okay, you have a frontend React app and you want to serve it via Docker. Let's do that!&lt;/p&gt;

&lt;p&gt;In this wiki, we will dockerize both the development and production environment via separate Dockerfiles.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 1: Project setup
&lt;/h2&gt;

&lt;p&gt;Initialized a pretty standard react project using the default &lt;a href="https://github.com/facebook/create-react-app"&gt;create react app&lt;/a&gt; (CRA) template. Or pick your existing React app. Below is the sample project folder structure.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; node_modules
 public
    favicon.ico
    index.html
    manifest.json
    robots.txt
 src
    App.css
    App.js
    index.css
    index.js
    logo.svg
 package.json
 yarn.lock

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Step 2: Init .dockerignore
&lt;/h2&gt;

&lt;p&gt;Add a &lt;code&gt;.dockerignore&lt;/code&gt; file, this will help us ignore &lt;code&gt;node_modules&lt;/code&gt;, &lt;code&gt;.env&lt;/code&gt; etc&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.git
.gitignore
**/node_modules
**/npm-debug.log
build

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Step 3: Dockerize Development env
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Init Dockerfile&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Start by adding a &lt;code&gt;Dockerfile.dev&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;FROM node:14-alpine AS development
ENV NODE_ENV development

# Add a work directory
WORKDIR /app

# Cache and Install dependencies
COPY package.json .
COPY yarn.lock .

#RUN yarn install
RUN npm i

# Copy app files
COPY . .

# Expose port
EXPOSE 3000

# Start the app
CMD ["yarn", "start"]

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Init docker-compose&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Create a &lt;code&gt;docker-compose.dev.yml&lt;/code&gt;. Additionally, we will mount our code in a &lt;a href="https://www.cloudsavvyit.com/7500/what-are-docker-volumes-and-how-do-you-use-them/"&gt;volume&lt;/a&gt; so that our code changes are in sync with the container during development.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;version: "3.8"

services:
  app:
    container_name: app-dev-c
    image: app-dev-i
    build:
      context: .
      dockerfile: Dockerfile.dev
    volumes:
      - ./src:/app/src
    ports:
      - "3000:3000"

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's start our React app for development!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker-compose -f docker-compose.dev.yml up

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To make life easier add docker-compose commands to &lt;code&gt;package.json&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;"docker-dev-up": "docker-compose -f docker-compose.dev.yml up"
"docker-dev-down": "docker-compose -f docker-compose.dev.yml down"

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's check our container!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt; docker ps

REPOSITORY TAG IMAGE ID CREATED SIZE
app-dev latest 5867f4e40c98 About a minute ago 436MB

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Visit the app at &lt;a href="http://localhost:3000"&gt;&lt;code&gt;http://localhost:3000&lt;/code&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  Step 4: Dockerize Production env
&lt;/h2&gt;

&lt;p&gt;Let's use &lt;a href="https://www.nginx.com/"&gt;nginx&lt;/a&gt; to serve our static assets and help resolve routes when we're using &lt;a href="https://reactrouter.com/"&gt;React Router&lt;/a&gt; or any kind of routing.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Configure nginx&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Create a &lt;code&gt;nginx.conf&lt;/code&gt; with the below content. This will help handle URI changes during routing.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;server {
  listen 80;

  location / {
    root /usr/share/nginx/html/;
    include /etc/nginx/mime.types;
    try_files $uri $uri/ /index.html;
  }
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Init Dockerfile&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Start by adding a &lt;code&gt;Dockerfile.prod&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;FROM node:14-alpine AS builder
ENV NODE_ENV production

# Add a work directory
WORKDIR /app

# Cache and Install dependencies
COPY package.json .
COPY yarn.lock .
RUN npm i

# Copy app files
COPY . .

# Build the app
RUN npm run build

# Bundle static assets with nginx
FROM nginx:1.21.0-alpine as production
ENV NODE_ENV production

# Copy built assets from builder
COPY --from=builder /app/build /usr/share/nginx/html

# Add your nginx.conf
COPY nginx.conf /etc/nginx/conf.d/default.conf

# Expose port
EXPOSE 80

# Start nginx
CMD ["nginx", "-g", "daemon off;"]

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Init docker-compose&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Add a &lt;code&gt;docker-compose.prod.yml&lt;/code&gt; file&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;version: "3.8"

services:
  app:
    container_name: app-prod-c
    image: app-prod-i
    build:
      context: .
      dockerfile: Dockerfile.prod
    ports:
        - "8080:80"

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Build production image&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker-compose -f docker-compose.prod.yml build

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's check out our built production image&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt; docker images

REPOSITORY TAG IMAGE ID CREATED SIZE
app-prod latest c5db8d308bb9 About a minute ago 23.1MB

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Start our production container on port &lt;code&gt;80&lt;/code&gt; with the name &lt;code&gt;react-app&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;docker run -p 8080:80 --name react-app app-prod

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Visit the app at &lt;a href="http://localhost:3000"&gt;&lt;code&gt;http://localhost:&lt;/code&gt;&lt;/a&gt;&lt;code&gt;8080&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Here is how the final project struct looks:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; node_modules
 public
    index.html
   ...
    manifest.json
 src
    App.css
   ...
    index.js
 package.json
 yarn.lock
 .dockerignore
 Dockerfile.dev
 Dockerfile.prod
 docker-compose.dev.yml
 docker-compose.prod.yml

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Hurrayyy!! We can now use docker in our workflow and deploy our production images faster to any platform.&lt;/p&gt;

</description>
      <category>react</category>
      <category>docker</category>
      <category>container</category>
      <category>dockercompose</category>
    </item>
    <item>
      <title>Host React app in GitHub pages</title>
      <dc:creator>Vishnu Prasaath</dc:creator>
      <pubDate>Tue, 11 Apr 2023 04:11:36 +0000</pubDate>
      <link>https://dev.to/pvishnuprasaath/host-react-app-in-github-pages-35p9</link>
      <guid>https://dev.to/pvishnuprasaath/host-react-app-in-github-pages-35p9</guid>
      <description>&lt;p&gt;There is a lot of documentation out there to host your react app on GitHub pages for FREE, which is accessible via &lt;code&gt;https://&amp;lt;git_user&amp;gt;.github.io/&amp;lt;repo_name&amp;gt;&lt;/code&gt;&lt;br&gt;&lt;br&gt;
&lt;strong&gt;ex:&lt;/strong&gt; &lt;code&gt;adam.github.io/portfolio&lt;/code&gt; , &lt;code&gt;vishnu.github.io/my-dev&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;But this doc will guide you to host react app at &lt;code&gt;https://&amp;lt;git_user&amp;gt;.github.io&lt;/code&gt; (no need to cling the repo name with URL)&lt;br&gt;&lt;br&gt;
&lt;strong&gt;ex:&lt;/strong&gt; &lt;code&gt;adam.github.io&lt;/code&gt; , &lt;code&gt;vishnu.github.io&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This approach is preferred for hosting a portfolio or dev-profile website.&lt;/p&gt;

&lt;p&gt;There are three types of GitHub Pages sites:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;User Site&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Project Site&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Organization Site&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This blog is inclined toward setting up a &lt;strong&gt;User Site&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Let's get started!&lt;/strong&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Step 1 - Create a repo on GitHub
&lt;/h3&gt;

&lt;p&gt;Create a new &lt;strong&gt;GitHub repo&lt;/strong&gt; named username.github.io (replace username with your current git user name) and make it &lt;strong&gt;Public&lt;/strong&gt; (to host private repo in GH pages you need a GitHub Enterprise account)&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1681028943747%2Fa7b5d1b9-a715-4e76-8f62-5f486395f5be.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%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1681028943747%2Fa7b5d1b9-a715-4e76-8f62-5f486395f5be.png" alt="img1"&gt;&lt;/a&gt;&lt;/p&gt;


&lt;h3&gt;
  
  
  Step 2 - Create React app and Push to repo
&lt;/h3&gt;

&lt;p&gt;Create your react app following the official doc - &lt;a href="https://create-react-app.dev/docs/getting-started/" rel="noopener noreferrer"&gt;https://create-react-app.dev/docs/getting-started/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Init &lt;strong&gt;git&lt;/strong&gt; and &lt;strong&gt;push&lt;/strong&gt; it to the above-created repo&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git init
git commit -m "first commit"
git branch -M main
git remote add origin https://github.com/username/username.github.io.git
git push -u origin main

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  Step 3 - Setup gh-pages
&lt;/h3&gt;

&lt;p&gt;The npm package &lt;a href="https://www.npmjs.com/package/gh-pages" rel="noopener noreferrer"&gt;gh-pages&lt;/a&gt; helps in configuring and deploying your app to GitHub pages&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install gh-pages save-dev

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Homepage property&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Add the below &lt;code&gt;homepage&lt;/code&gt; property to your &lt;code&gt;package.json&lt;/code&gt; file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;For free GitHub user site, add this: 
"homepage": "https://{username}.github.io"

If you own a domain, add this:
"homepage": "https://mydomainname.com"

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1681030015020%2Fbc19bfff-fb70-457e-b0ff-6a0e5a2ab97d.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%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1681030015020%2Fbc19bfff-fb70-457e-b0ff-6a0e5a2ab97d.png" alt="img2"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Deploy Script&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Add both &lt;strong&gt;predeploy&lt;/strong&gt; and &lt;strong&gt;deploy&lt;/strong&gt; property scripts to the &lt;code&gt;package.json&lt;/code&gt; as below&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"predeploy": "npm run build",
"deploy": "gh-pages -d build"

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;predeploy&lt;/strong&gt; - bundle the react application&lt;br&gt;&lt;br&gt;
&lt;strong&gt;deploy&lt;/strong&gt; - deploy the bundled file.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1681030290187%2F7fb123aa-6a9a-4864-9b67-b36cba2bbbf1.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%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1681030290187%2F7fb123aa-6a9a-4864-9b67-b36cba2bbbf1.png" alt="img3"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Push these changes to the git repo&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 -m "configure gh-pages"
git push

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  Step 4 - Deploy the app to GitHub Pages
&lt;/h3&gt;

&lt;p&gt;Run the below command to deploy your react application to GitHub Pages&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm run deploy

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  Step 5 - Finally access the deployed site
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Go to the GitHub repo&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Click &lt;strong&gt;Settings&lt;/strong&gt; menu&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Go to the &lt;strong&gt;Code and Automation&lt;/strong&gt; -&amp;gt; &lt;strong&gt;Pages&lt;/strong&gt; section&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;In the &lt;strong&gt;Build and Deployment&lt;/strong&gt; section, select &lt;strong&gt;Source&lt;/strong&gt; to &lt;strong&gt;Deploy from a branch&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Select the &lt;strong&gt;branch&lt;/strong&gt; to &lt;strong&gt;"gh-pages"&lt;/strong&gt; and click on the &lt;strong&gt;"Save"&lt;/strong&gt; button&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1681030949821%2F769b9096-2a16-4702-8a6a-03f0b1b632a5.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%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1681030949821%2F769b9096-2a16-4702-8a6a-03f0b1b632a5.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Visit &lt;code&gt;username.github.io&lt;/code&gt; and check out your site.&lt;/p&gt;

&lt;p&gt;Yayy!&lt;/p&gt;

&lt;p&gt;Your website is hosted for FREEEE in GitHub Pages and accessible to the world.&lt;/p&gt;

</description>
      <category>react</category>
      <category>hosting</category>
      <category>githubpages</category>
      <category>github</category>
    </item>
  </channel>
</rss>
