<?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: Soham De Roy</title>
    <description>The latest articles on DEV Community by Soham De Roy (@sohamderoy).</description>
    <link>https://dev.to/sohamderoy</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%2F402601%2Fcb045312-3ac5-4e20-a081-f9c46c71967f.jpg</url>
      <title>DEV Community: Soham De Roy</title>
      <link>https://dev.to/sohamderoy</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/sohamderoy"/>
    <language>en</language>
    <item>
      <title>Understanding Redux (Part 2): Creating a small Redux powered React App in 10 easy steps (with code snippets)</title>
      <dc:creator>Soham De Roy</dc:creator>
      <pubDate>Thu, 26 May 2022 10:35:16 +0000</pubDate>
      <link>https://dev.to/sohamderoy/understanding-redux-part-2-creating-a-small-redux-powered-react-app-in-10-easy-steps-with-code-snippets-4clb</link>
      <guid>https://dev.to/sohamderoy/understanding-redux-part-2-creating-a-small-redux-powered-react-app-in-10-easy-steps-with-code-snippets-4clb</guid>
      <description>&lt;p&gt;Before proceeding with this blog, I would recommend first going through Part 1 of the Understanding Redux series which can be found by clicking on this link &lt;a href="https://dev.to/sohamderoy/understanding-redux-part-1-demystifying-store-action-and-reducers-k4j"&gt;Understanding Redux (Part 1): Demystifying Store, Action and Reducers&lt;/a&gt;. That will help you understand the current article. In the Part 1 blog, &lt;strong&gt;I have tried to explain the fundamental principles/ concepts of Redux&lt;/strong&gt;. I have covered what is &lt;strong&gt;Store&lt;/strong&gt;, &lt;strong&gt;Actions&lt;/strong&gt;, and &lt;strong&gt;Reducers&lt;/strong&gt;, what makes &lt;strong&gt;Redux predictable&lt;/strong&gt; along with an example. &lt;/p&gt;

&lt;p&gt;In this current article, we will try to set up our own &lt;strong&gt;redux powered react application&lt;/strong&gt;. We will go through how to &lt;strong&gt;create Store and provide it to the Application&lt;/strong&gt;, &lt;strong&gt;write Actions&lt;/strong&gt;, &lt;strong&gt;Dispatch them on user interactions&lt;/strong&gt;, &lt;strong&gt;make Reducers and update the store&lt;/strong&gt;, &lt;strong&gt;read the store from other components which are children of App&lt;/strong&gt; and many more. I'll provide all the important code snippets along the way so that you can quickly spin up the application.&lt;/p&gt;

&lt;p&gt;To give a glimpse in the beginning itself, this is what we will finally build&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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdmxjeagszvav1uhcv0b2.gif" 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%2Fuploads%2Farticles%2Fdmxjeagszvav1uhcv0b2.gif" alt="finalAppDemo"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We will be creating a basic application where we can add and remove item in the cart. We will manage the state changes in the redux store and display the information in the UI.&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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fibmtgpwwf6ark0elvp8u.gif" 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%2Fuploads%2Farticles%2Fibmtgpwwf6ark0elvp8u.gif" alt="letsGetStartedGif"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Code Setup
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. Create a react app with the create-react-app command
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npx create-react-app react-app-with-redux
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  2. Go to the newly created folder using
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd react-app-with-redux
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  3. Install &lt;strong&gt;redux&lt;/strong&gt; and &lt;strong&gt;react-redux&lt;/strong&gt; library using the commands
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install redux react-redux

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

&lt;/div&gt;



&lt;h3&gt;
  
  
  4. Run the application using
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm start
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  5. Creating Reducer
&lt;/h3&gt;

&lt;p&gt;First create a folder inside &lt;code&gt;src&lt;/code&gt; named &lt;code&gt;actionTypes&lt;/code&gt; and create a file inside it named &lt;code&gt;actionTypes.js&lt;/code&gt;. This file will contain all the &lt;strong&gt;actions&lt;/strong&gt; the application will be dealing with. Add the following lines in &lt;code&gt;actionTypes.js&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;export const ADD_ITEM = "ADD_ITEM";
export const DELETE_ITEM = "DELETE_ITEM";
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As we are making an app where we will have the functionality of adding and deleting an Item, hence the above two action types.&lt;/p&gt;

&lt;p&gt;Next create a folder inside the &lt;code&gt;src&lt;/code&gt; called &lt;code&gt;reducers&lt;/code&gt; and create a new file in it named &lt;code&gt;cartReducer.js&lt;/code&gt;. This file will contain all the reducer logic related to the &lt;strong&gt;cart&lt;/strong&gt; component. &lt;em&gt;(&lt;/em&gt;&lt;em&gt;Note&lt;/em&gt;&lt;em&gt;: We will create the view/ UI in the step 8)&lt;/em&gt;. Add the following lines in the &lt;code&gt;cartReducer.js&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;import { ADD_ITEM, DELETE_ITEM } from "../actionTypes/actionTypes";

const initialState = {
  numOfItems: 0,
};

export default const cartReducer = (state = initialState, action) =&amp;gt; {
  switch (action.type) {
    case ADD_ITEM:
      return {
        ...state,
        numOfItems: state.numOfItems + 1,
      };

    case DELETE_ITEM:
      return {
        ...state,
        numOfItems: state.numOfItems - 1,
      };
    default:
      return state;
  }
};

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

&lt;/div&gt;



&lt;p&gt;As we discussed it &lt;a href="https://dev.to/sohamderoy/understanding-redux-part-1-demystifying-store-action-and-reducers-k4j"&gt;Part 1&lt;/a&gt; of this blog, we created an &lt;strong&gt;initial state&lt;/strong&gt; for the app and assigned it to the default parameter of &lt;code&gt;state&lt;/code&gt; in the &lt;code&gt;cartReducer&lt;/code&gt; function. This function switches on the &lt;strong&gt;type of action&lt;/strong&gt; dispatched, and which ever case matches with the action type, makes necessary changes in the state and returns a fresh new instance of the updated state. If none of the action type matches, then the state is returned as it is. Finally we make a &lt;strong&gt;default export&lt;/strong&gt; of the &lt;code&gt;cakeReducer&lt;/code&gt; function to use it in the store creation process.&lt;/p&gt;

&lt;h3&gt;
  
  
  6. Creating the store and providing it to the App
&lt;/h3&gt;

&lt;p&gt;Create a file inside &lt;code&gt;src&lt;/code&gt; with the name &lt;code&gt;store.js&lt;/code&gt; and create the store using the command&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const store = createStore()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Add the following lines in &lt;code&gt;store.js&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;import { createStore } from "redux";
import { cartReducer } from "./reducers/cartReducer";

const store = createStore(cartReducer);

export default store;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now it's time to provide this &lt;code&gt;store&lt;/code&gt; to the &lt;code&gt;App&lt;/code&gt; component. For this we make use of the &lt;code&gt;&amp;lt;Provider&amp;gt;&lt;/code&gt; tag that we get from the &lt;code&gt;react-redux&lt;/code&gt; library. We wrap the whole &lt;code&gt;App&lt;/code&gt; component inside the &lt;code&gt;&amp;lt;Provider&amp;gt;&lt;/code&gt; tag using the following syntax.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// rest of the code ...

&amp;lt;Provider store={store}&amp;gt;
        &amp;lt;div&amp;gt;App Component&amp;lt;/div&amp;gt;
        // child components of App/ other logic
&amp;lt;/Provider&amp;gt;

// rest of the code ...
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;By wrapping the &lt;code&gt;App&lt;/code&gt; component inside the &lt;code&gt;&amp;lt;Provider&amp;gt;&lt;/code&gt; tag, all the children component of &lt;code&gt;App&lt;/code&gt; will get access of the &lt;code&gt;store&lt;/code&gt;. Please visit the &lt;a href="https://dev.to/sohamderoy/understanding-redux-part-1-demystifying-store-action-and-reducers-k4j"&gt;Part 1&lt;/a&gt; of the blog series to know more.&lt;/p&gt;

&lt;p&gt;Continuing with the &lt;code&gt;App.js&lt;/code&gt;, add the following lines in the file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import "./App.css";
import { Provider } from "react-redux";
import store from "./store";

function App() {
  return (
    &amp;lt;Provider store={store}&amp;gt;
      &amp;lt;div&amp;gt;App Component&amp;lt;/div&amp;gt;
    &amp;lt;/Provider&amp;gt;
  );
}

export default App;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  7. Create Actions
&lt;/h3&gt;

&lt;p&gt;Now create a folder inside &lt;code&gt;src&lt;/code&gt; called &lt;code&gt;actions&lt;/code&gt; and create a file inside it called &lt;code&gt;cartAction.js&lt;/code&gt;. Here we will add all the actions to be &lt;strong&gt;dispatched&lt;/strong&gt; on some user interactions. Add the following lines in the &lt;code&gt;cartAction.js&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;import { ADD_ITEM, DELETE_ITEM } from "../actionTypes/actionTypes";

const addItem = () =&amp;gt; {
  return {
    type: ADD_ITEM,
  };
};

const deleteItem = () =&amp;gt; {
  return {
    type: DELETE_ITEM,
  };
};

export { addItem, deleteItem };
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above code we created two action creators &lt;em&gt;(pure JS functions that returns &lt;code&gt;action&lt;/code&gt; object)&lt;/em&gt; called &lt;code&gt;addItem()&lt;/code&gt; and &lt;code&gt;deleteItem()&lt;/code&gt;. Both the &lt;strong&gt;action creators&lt;/strong&gt; returns &lt;code&gt;action&lt;/code&gt; object with a specific &lt;code&gt;type&lt;/code&gt;. &lt;strong&gt;Note&lt;/strong&gt;: Each &lt;code&gt;action&lt;/code&gt; object &lt;strong&gt;must necessarily&lt;/strong&gt; have a unique &lt;code&gt;type&lt;/code&gt; value. Along with it any additional data passed with the action object is optional and will depend on the logic used for updating the &lt;code&gt;state&lt;/code&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  8. Creating the view/ UI
&lt;/h3&gt;

&lt;p&gt;Now that we have created all the required entities such as &lt;strong&gt;Store, Actions, and Reducers&lt;/strong&gt;, it's time to create the UI elements. Create a &lt;code&gt;component&lt;/code&gt; folder inside &lt;code&gt;src&lt;/code&gt; and create a &lt;code&gt;Cart.js&lt;/code&gt; file inside it. Add the following line inside &lt;code&gt;Cart.js&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;import React from "react";

const Cart = () =&amp;gt; {
  return (
    &amp;lt;div className="cart"&amp;gt;
      &amp;lt;h2&amp;gt;Number of items in Cart:&amp;lt;/h2&amp;gt;
      &amp;lt;button className="green"&amp;gt;Add Item to Cart&amp;lt;/button&amp;gt;
      &amp;lt;button className="red"&amp;gt;Remove Item from Cart&amp;lt;/button&amp;gt;
    &amp;lt;/div&amp;gt;
  );
};

export default Cart;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Add this &lt;code&gt;Cart&lt;/code&gt; component in the &lt;code&gt;App.js&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;import "./App.css";
import { Provider } from "react-redux";
import store from "./store";
import Cart from "./component/Cart";

function App() {
  return (
    &amp;lt;Provider store={store}&amp;gt;
      &amp;lt;Cart /&amp;gt;
    &amp;lt;/Provider&amp;gt;
  );
}

export default App;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Just to make it a bit presentable, I have added a bit of basic styling in the &lt;code&gt;App.css&lt;/code&gt; as follows.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;button {
  margin: 10px;
  font-size: 16px;
  letter-spacing: 2px;
  font-weight: 400;
  color: #fff;
  padding: 23px 50px;
  text-align: center;
  display: inline-block;
  text-decoration: none;
  border: 0px;
  cursor: pointer;
}
.green {
  background-color: rgb(6, 172, 0);
}
.red {
  background-color: rgb(221, 52, 66);
}
.red:disabled {
  background-color: rgb(193, 191, 191);
  cursor: not-allowed;
}
.cart {
  text-align: center;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is how the UI looks as of now&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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhjfabtnn63fwgtz8stew.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%2Fuploads%2Farticles%2Fhjfabtnn63fwgtz8stew.png" alt="uiAfterCss"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  9. Reading/ Accessing the store using &lt;code&gt;useSelector&lt;/code&gt; hook
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;useSelector&lt;/code&gt; is a hook provided by the &lt;strong&gt;react-redux&lt;/strong&gt; library that helps us in reading the &lt;code&gt;store&lt;/code&gt; and thus its content(s). Import the hook from &lt;code&gt;react-redux&lt;/code&gt; and use the following syntax to read the store with &lt;code&gt;useSelector&lt;/code&gt; hook&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { useSelector } from "react-redux";
// rest of the code
const state = useSelector((state) =&amp;gt; state);

// rest of the code
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Thus after adding &lt;code&gt;useSelector&lt;/code&gt; hook, &lt;code&gt;Cart.js&lt;/code&gt; file will look some thing like this&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React from "react";
import { useSelector } from "react-redux";

const Cart = () =&amp;gt; {
  const state = useSelector((state) =&amp;gt; state);
  console.log("store", state);
  return (
    &amp;lt;div className="cart"&amp;gt;
      &amp;lt;h2&amp;gt;Number of items in Cart:&amp;lt;/h2&amp;gt;
      &amp;lt;button className="green"&amp;gt;Add Item to Cart&amp;lt;/button&amp;gt;
      &amp;lt;button className="red"&amp;gt;Remove Item from Cart&amp;lt;/button&amp;gt;
    &amp;lt;/div&amp;gt;
  );
};

export default Cart;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;console logging the state will give us the initial state that we set in the reducer file in step 5.&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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fl2gr9k3wkfb7kcc6l6lh.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%2Fuploads%2Farticles%2Fl2gr9k3wkfb7kcc6l6lh.png" alt="consoleSS"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  10. Dispatching Action on button click (along with handling some UI behaviour based on the state) with &lt;code&gt;useDispatch&lt;/code&gt; hook
&lt;/h3&gt;

&lt;p&gt;The &lt;strong&gt;react-redux&lt;/strong&gt; library gives us another hook called the &lt;code&gt;useDispatch&lt;/code&gt; hook, that helps us dispatching the &lt;strong&gt;actions&lt;/strong&gt; or &lt;strong&gt;action creators&lt;/strong&gt; which in turn &lt;strong&gt;returns actions&lt;/strong&gt;. The syntax is as follows&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const dispatch = useDispatch();

dispatch(actionObject or calling the action creator);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Thus adding a dispatcher into our &lt;code&gt;Cart.js&lt;/code&gt; will finally make the file look some thing like this&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React from "react";
import { useSelector, useDispatch } from "react-redux";
import { addItem, deleteItem } from "../actions/cartAction";

const Cart = () =&amp;gt; {
  const state = useSelector((state) =&amp;gt; state);
  const dispatch = useDispatch();
  return (
    &amp;lt;div className="cart"&amp;gt;
      &amp;lt;h2&amp;gt;Number of items in Cart: {state.numOfItems}&amp;lt;/h2&amp;gt;
      &amp;lt;button
        onClick={() =&amp;gt; {
          dispatch(addItem());
        }}
      &amp;gt;
        Add Item to Cart
      &amp;lt;/button&amp;gt;
      &amp;lt;button
        disabled={state.numOfItems &amp;gt; 0 ? false : true}
        onClick={() =&amp;gt; {
          dispatch(deleteItem());
        }}
      &amp;gt;
        Remove Item to Cart
      &amp;lt;/button&amp;gt;
    &amp;lt;/div&amp;gt;
  );
};

export default Cart;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note how on click on the &lt;strong&gt;Add Item to Cart&lt;/strong&gt; button, we &lt;code&gt;dispatch&lt;/code&gt; the action creator &lt;code&gt;addItem()&lt;/code&gt; that we created in step no. 7. Similarly on click on the &lt;strong&gt;Remove Item from Cart&lt;/strong&gt; button, we dispatch the action creator &lt;code&gt;deleteItem()&lt;/code&gt;. The &lt;code&gt;state&lt;/code&gt; variable stores the state of the app, which is basically an object with a key &lt;code&gt;numOfItems&lt;/code&gt;. Thus &lt;code&gt;state.numOfItems&lt;/code&gt; gives us the current number of items value in the store. We display this in the view in the line &lt;code&gt;&amp;lt;h2&amp;gt;Number of items in Cart: {state.numOfItems}&amp;lt;/h2&amp;gt;&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;To dig a bit deeper, when the &lt;strong&gt;Add Item to Cart&lt;/strong&gt; button is clicked, it dispatches the &lt;code&gt;addItem()&lt;/code&gt; action creator, which in turn returns an &lt;code&gt;action&lt;/code&gt; object with &lt;strong&gt;type&lt;/strong&gt; &lt;code&gt;type: ADD_ITEM&lt;/code&gt;. As mentioned in &lt;a href="https://dev.to/sohamderoy/understanding-redux-part-1-demystifying-store-action-and-reducers-k4j"&gt;Part 1&lt;/a&gt; of this blog series, when an action is dispatched, all the reducers becomes active. Currently in this example we have only one reducer i.e. &lt;code&gt;cartReducer&lt;/code&gt;, thus it becomes active and listens to the &lt;code&gt;action&lt;/code&gt; dispatched. As shown in step 5, the reducer takes the state and the action as input, switches on the &lt;code&gt;action type&lt;/code&gt; and &lt;strong&gt;returns the fresh new instance of the updated state&lt;/strong&gt;. In this example, when the action with &lt;code&gt;type: ADD_ITEM&lt;/code&gt;, matches the first switch case, it first make a copy of the entire state using spread operator &lt;code&gt;...state&lt;/code&gt;, and then make the necessary update which in the case of adding item is &lt;code&gt;numOfItems: state.numOfItems + 1&lt;/code&gt; i.e. &lt;strong&gt;increasing&lt;/strong&gt; the &lt;code&gt;numOfItems&lt;/code&gt; by 1. &lt;/p&gt;

&lt;p&gt;Similarly, using the same logic, on clicking on the &lt;strong&gt;Remove Item from Cart&lt;/strong&gt; button, an action with &lt;strong&gt;type&lt;/strong&gt; &lt;code&gt;type: DELETE_ITEM&lt;/code&gt; is dispatched which goes and &lt;strong&gt;decreases&lt;/strong&gt; the &lt;code&gt;numOfItems&lt;/code&gt; by 1. &lt;/p&gt;

&lt;p&gt;Here is the demo of the working app.&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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fccobehkve5mc6xxsazp2.gif" 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%2Fuploads%2Farticles%2Fccobehkve5mc6xxsazp2.gif" alt="finalAppDemo"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Notice how we were able to control the behaviour of the &lt;strong&gt;Remove Item from Cart&lt;/strong&gt; button based on the value of &lt;code&gt;numOfItems&lt;/code&gt; in the &lt;strong&gt;redux store&lt;/strong&gt;. As a negative number of items does not makes sense, we disabled the &lt;strong&gt;Remove Item from Cart&lt;/strong&gt; button if &lt;code&gt;state.numOfItems &amp;lt;= 0&lt;/code&gt;. This way we are able to restrict the user from decreasing the number of items in the cart if its already 0. This was a basic example to show how we can &lt;strong&gt;control the behaviour of various DOM elements&lt;/strong&gt; based on internal state of the app.&lt;/p&gt;

&lt;h2&gt;
  
  
  Github Link
&lt;/h2&gt;

&lt;p&gt;Github link of the project can be found here: &lt;a href="https://github.com/sohamderoy/blog-setup-react-app-with-redux/tree/master" rel="noopener noreferrer"&gt;Github Link&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Summary
&lt;/h2&gt;

&lt;p&gt;In this article, we learnt how to quickly spin up a &lt;strong&gt;redux&lt;/strong&gt; powered &lt;strong&gt;react&lt;/strong&gt; application. We learnt how to&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Create Actions, Action creators, Reducers and Store&lt;/li&gt;
&lt;li&gt;Provide the Store to the App using &lt;code&gt;&amp;lt;Provider&amp;gt;&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Read/ access the Store from components using &lt;code&gt;useSelector&lt;/code&gt; hook and display the state information in the UI&lt;/li&gt;
&lt;li&gt;Dispatch the actions on user events such as button clicks, using &lt;code&gt;useDispatch&lt;/code&gt; hook&lt;/li&gt;
&lt;li&gt;Control DOM element's behaviour with logic based on the state of the application&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Wrapup
&lt;/h2&gt;

&lt;p&gt;Thanks for reading! I really hope you enjoyed reading about how to spin up a redux powered react application and found this blog useful. Do consider hitting the like button and sharing it with your friends, I'd really appreciate that. Stay tuned for more amazing content! Peace out! 🖖&lt;/p&gt;

&lt;h2&gt;
  
  
  Social Links
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="//linkedin.com/in/sohamderoy"&gt;LinkedIn&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="//www.sohamderoy.dev"&gt;Website&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="//blog.sohamderoy.dev"&gt;Blog site&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>javascript</category>
      <category>react</category>
      <category>redux</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Understanding Redux (Part 1): Demystifying Store, Action and Reducers</title>
      <dc:creator>Soham De Roy</dc:creator>
      <pubDate>Wed, 18 May 2022 19:18:34 +0000</pubDate>
      <link>https://dev.to/sohamderoy/understanding-redux-part-1-demystifying-store-action-and-reducers-k4j</link>
      <guid>https://dev.to/sohamderoy/understanding-redux-part-1-demystifying-store-action-and-reducers-k4j</guid>
      <description>&lt;h1&gt;
  
  
  Introduction
&lt;/h1&gt;

&lt;p&gt;&lt;em&gt;As a pre-requisite, I will be assuming that the readers of this article are familiar with React.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;As per the official docs of Redux, it is a &lt;strong&gt;Predictable State Container for JS Apps&lt;/strong&gt;. If we try to dig deep into this statement, it's very much clear that Redux is a state management library that can be used with any JS library or framework like React, Angular, Vue etc. &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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fakh18elbkkjm1oorkx0h.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%2Fuploads%2Farticles%2Fakh18elbkkjm1oorkx0h.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Why is redux termed as a state container?
&lt;/h2&gt;

&lt;p&gt;Well, an application has its state, which in turn can be a combination of the states of its internal components. Let's take an e-commerce website for example. An e-commerce website will have several components like the cart component, user profile component, previously viewed section component etc. Let's take the cart component for e.g. which displays the number of items in the cart of a user. The state of the cart component will comprise of all the items the user has added to the cart and the total number of such items. At all the times the application is up and running, this component has to show the updated number of items in the cart of the user. &lt;/p&gt;

&lt;p&gt;Whenever a user adds an item to the cart, the application has to internally handle that action by adding that item to the cart object, maintaining its state internally and also it has to show the user the total number of items in the cart in the UI. Similarly, removing an item from the cart should decrease the number of items in the cart internally, remove the item from the cart object and also display the updated total number of items in the cart in the UI. &lt;/p&gt;

&lt;p&gt;We may very well maintain the internal state of the components inside them, but as and when an application grows bigger, it may have to share some state between components, not just only to show them in the view, but also to manage/ update them or perform some logic based on their value. This part of handling multiple states from multiple components efficiently can become a challenging task when the application grows in size.&lt;/p&gt;

&lt;p&gt;This is where Redux comes into the picture. Being a state management library, Redux will basically store and manage all the application's states. It also provides us with some important APIs using which we can make changes to the existing state as well as fetch the current state of the application. &lt;/p&gt;

&lt;h2&gt;
  
  
  What makes Redux predictable?
&lt;/h2&gt;

&lt;p&gt;The state is &lt;strong&gt;Read-only&lt;/strong&gt; in redux. What makes Redux predictable is to make a change in the state of the application we need to dispatch an action which describes what changes we want to do in the state. These actions are then consumed by something known as reducers, whose sole job is to accept two thing i.e. action and the current state of the application and return a new updated instance of the state. &lt;em&gt;(Actions and Reducers are described further in the following sections.)&lt;/em&gt; Note that reducers do not change any part of the state. Rather it produces a new instance of the state with all the necessary updates. According to @&lt;a href="https://dev.to@gaearon"&gt;Dan Abramov&lt;/a&gt; &lt;em&gt;(the creator of Redux)&lt;/em&gt; himself "Actions can be recorded and replayed later, so this makes state management predictable. With the same actions in the same order, you're going to end up in the same state." Thus continuing with our above example of an e-commerce website, if the initial state of the Cart is that it has 0 items, then an action of &lt;strong&gt;adding one item&lt;/strong&gt; to the cart will increase the number of items in the cart to 1. Again firing the action of &lt;strong&gt;adding one item&lt;/strong&gt; to the cart will increase the number of items in the cart to 2. Given an initial state, with a specific list of &lt;strong&gt;actions&lt;/strong&gt; in a specific order, will always provide us with the exact same final state of the entity. This is how Redux makes state management predictable.&lt;/p&gt;

&lt;p&gt;In the following section, we will dive deep into the core concepts of redux i.e. store, actions and reducers.&lt;/p&gt;

&lt;h2&gt;
  
  
  Core Principles of Redux
&lt;/h2&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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwf98evl323hm9dcj2cc6.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%2Fuploads%2Farticles%2Fwf98evl323hm9dcj2cc6.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Store
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;The global state of an application is stored in an object tree within a single store&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The Redux store is the main, central bucket which stores all the states of an application. It should be considered and maintained as a &lt;strong&gt;single source of truth&lt;/strong&gt;, for the state of the application. If the &lt;code&gt;store&lt;/code&gt; is provided to the &lt;strong&gt;App.js&lt;/strong&gt; (by wrapping the &lt;code&gt;App&lt;/code&gt; component within the &lt;code&gt;&amp;lt;Provider&amp;gt;&lt;/code&gt; &lt;code&gt;&amp;lt;/Provider&amp;gt;&lt;/code&gt; tag) as shown in the code snippet below, then all its children (children components of &lt;code&gt;App.js&lt;/code&gt;) can also access the state of the application from the store, thus making it act as a global state.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// src/index.js

import React from 'react'
import ReactDOM from 'react-dom'
import { Provider } from 'react-redux'

import { App } from './App'
import createStore from './createReduxStore'

const store = createStore()

// As of React 18
const root = ReactDOM.createRoot(document.getElementById('root'))
root.render(
  &amp;lt;Provider store={store}&amp;gt;
    &amp;lt;App /&amp;gt;
  &amp;lt;/Provider&amp;gt;
)

&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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fe5lea1yanax7r7mcgdks.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%2Fuploads%2Farticles%2Fe5lea1yanax7r7mcgdks.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The state of the whole application is stored in the form of a &lt;strong&gt;JS object tree&lt;/strong&gt; in a &lt;strong&gt;single store&lt;/strong&gt; as shown below.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// this is how the store object structure looks like
{
    noOfItemInCart: 2,
    cart: [
        {
            bookName: "Harry Potter and the Chamber of Secrets",
            noOfItem: 1,
        },
        {
            bookName: "Harry Potter and the Prisoner of Azkaban",
            noOfItem: 1
        }
    ]
}

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

&lt;/div&gt;



&lt;h3&gt;
  
  
  2. Action
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;The only way to change the state is to emit an action, which is an object describing what happened&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;As mentioned above, the state in redux is read-only. This helps in restricting any part of the view or any network calls to write/ update the state directly. Instead, if anyone wants to change the state of the application, then it needs to express its intention of doing so by &lt;strong&gt;emitting or dispatching an action&lt;/strong&gt;. &lt;/p&gt;

&lt;p&gt;Let's take the example of the above store example where we have 2 books in the store, namely &lt;em&gt;"Harry Potter and the Chamber of Secrets"&lt;/em&gt; and &lt;em&gt;"Harry Potter and the Prisoner of Azkaban"&lt;/em&gt; both having only one item for each. Now if the user wants to add another item to the cart, then he will have to click on the &lt;strong&gt;"Add to Cart"&lt;/strong&gt; button next to the item. &lt;/p&gt;

&lt;p&gt;On the click of the &lt;strong&gt;"Add to Cart"&lt;/strong&gt; button, an action will be dispatched where the &lt;strong&gt;action&lt;/strong&gt; is nothing but a JS object describing what changes need to be done in the store. Something like this&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Rest of the code

const dispatch = useDispatch()

const addItemToCart = () =&amp;gt; {
return {
    type: "ADD_ITEM_TO_CART"
    payload: {
        bookName: "Harry Potter and the Goblet of Fire",
        noOfItem: 1,
        }
    }
}


&amp;lt;button onClick = {() =&amp;gt; dispatch(addItemToCart())}&amp;gt;Add to cart&amp;lt;/button&amp;gt;

// Rest of the code
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note how in the above example, we dispatch an action on click of the button. Or rather to be more specific, we dispatch something known as an &lt;strong&gt;action creator&lt;/strong&gt; i.e. the function &lt;code&gt;addItemToCart()&lt;/code&gt;, which in turn returns an &lt;code&gt;action&lt;/code&gt; which is a plain JS object describing the purpose of the action denoted by the &lt;code&gt;type&lt;/code&gt; key along with any other data required for the state change (which in this case is the name of the book to be added to the cart denoted by the &lt;code&gt;payload&lt;/code&gt; key). &lt;strong&gt;Every action must compulsorily have at least&lt;/strong&gt; a &lt;code&gt;type&lt;/code&gt; associated with it. Any other detail that needs to be passed is optional and will depend on the type of action we dispatch. For e.g. the above code snippets dispatches the following action&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Action that got created by the action creator addItemToCart()

{
    type: "ADD_ITEM_TO_CART" // Note: Every action must have a type key
    payload: {
        bookName: "Harry Potter and the Goblet of Fire",
        noOfItem: 1,
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  3. Reducers
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;To specify how the state tree is transformed by actions, we write pure reducers&lt;/p&gt;
&lt;/blockquote&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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgcxyzymo25034gn7lsbd.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%2Fuploads%2Farticles%2Fgcxyzymo25034gn7lsbd.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Reducers, as the name suggests, take in &lt;strong&gt;two&lt;/strong&gt; things, i.e. &lt;strong&gt;previous state and an action&lt;/strong&gt; and reduce it (read it return) to one entity i.e. the &lt;strong&gt;new updated instance of state&lt;/strong&gt;. Thus reducers are basically &lt;strong&gt;pure JS functions&lt;/strong&gt; which take in the previous state and an action and return the newly updated state. There can be either one reducer if it is a simple app or multiple reducers taking care of different parts or slices of the global state in case of a bigger application. For e.g. there can be a reducer handling the state of the cart in a shopping application, then there can be a reducer handling the user's details part of the application etc. Whenever an action is dispatched, &lt;strong&gt;all the reducers are activated&lt;/strong&gt;. Each reducer filters out the action using a switch statement switching on the &lt;strong&gt;action type&lt;/strong&gt;. Whenever the switch statement matches with the action passed, the corresponding reducers take the necessary action to make the update and return a fresh new instance of the global state. Continuing with our above example we can have a reducer as follows&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
const initialCartState = {    
    noOfItemInCart: 0,          
    cart: []                              
}

// NOTE: 
// It is important to pass an initial state as default to 
// the state parameter to handle the case of calling 
// the reducers for the first time when the 
// state might be undefined

const cartReducer = (state = initialCartState, action) =&amp;gt; {
    switch (action.type) {
        case "ADD_ITEM_TO_CART": 
            return {
                ...state,
                noOfItemInCart: state.noOfItemInCart + 1,
                cart : [
                    ...state.cart,
                    action.payload
                ]
            }
        case "DELETE_ITEM_FROM_CART":
            return {
                // Remaining logic
            }
        default: 
            return state  
    }       // Important to handle the default behaviour
}           // either by returning the whole state as it is 
            // or by performing any required logic

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

&lt;/div&gt;



&lt;p&gt;In the above code snippet, we created a reducer called &lt;code&gt;cartReducer&lt;/code&gt; which is a pure JS function. This function accepts two parameters i.e. &lt;code&gt;state&lt;/code&gt; and &lt;code&gt;action&lt;/code&gt;. Note that the &lt;code&gt;state&lt;/code&gt; parameter is a default parameter which accepts an initial state. This is to handle the scenario when &lt;strong&gt;the reducer is called for the first time&lt;/strong&gt; when the &lt;code&gt;state&lt;/code&gt; value is &lt;code&gt;undefined&lt;/code&gt;.  Also note that every reducer should handle the &lt;code&gt;default&lt;/code&gt; case where if none of the switch cases matches with the passed action, then the reducer should return &lt;code&gt;state&lt;/code&gt; as it is or perform any required logic on it before passing the state.&lt;/p&gt;

&lt;p&gt;Whenever we dispatch an action with a certain type, we need to make sure to have &lt;strong&gt;appropriate reducers&lt;/strong&gt; to handle that action. In the above example, on clicking the button, we had dispatched an &lt;strong&gt;action&lt;/strong&gt; with an &lt;strong&gt;action creator&lt;/strong&gt; called &lt;code&gt;addItemToCart()&lt;/code&gt;. This action creator has dispatched an action with the &lt;code&gt;type&lt;/code&gt; &lt;code&gt;ADD_ITEM_TO_CART&lt;/code&gt;. Next, we have created a &lt;strong&gt;reducer&lt;/strong&gt; called &lt;code&gt;cartReducer&lt;/code&gt; which takes the state &lt;em&gt;(with the default initial state)&lt;/em&gt; and the action as parameters, switches on the &lt;strong&gt;action type&lt;/strong&gt;, and then whichever case matches with the dispatched action type, it makes the necessary update and &lt;strong&gt;returns the fresh new version of the updated state&lt;/strong&gt;. Please note here that the &lt;strong&gt;state in redux is immutable&lt;/strong&gt;. Hence, the reducers &lt;strong&gt;make a copy&lt;/strong&gt; of the entire current state first, make necessary changes and then &lt;strong&gt;return a fresh new instance of the state&lt;/strong&gt; with all the necessary changes/ updates. Thus in the above example, we first make a copy of the entire state using the spread operator &lt;code&gt;...state&lt;/code&gt;, then increment the &lt;code&gt;noOfItemInCart&lt;/code&gt; by 1, update the cart array by adding the new object passed in the &lt;code&gt;action.payload&lt;/code&gt; shown below and then finally return the updated object.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
    bookName: "Harry Potter and the Goblet of Fire",
    noOfItem: 1,
}

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

&lt;/div&gt;



&lt;p&gt;After the reducers have updated the state if we go and &lt;code&gt;console.log&lt;/code&gt; the &lt;code&gt;state&lt;/code&gt;, then we would see the following result.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Updated store

{
    noOfItemInCart: 3, // Incremented by 1
    cart: [
        {
            bookName: "Harry Potter and the Chamber of Secrets",
            noOfItem: 1,
        },
        {
            bookName: "Harry Potter and the Prisoner of Azkaban",
            noOfItem: 1
        },
        { // Newly added object
            bookName: "Harry Potter and the Goblet of Fire",
            noOfItem: 1,
        }
    ]
}

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

&lt;/div&gt;



&lt;h2&gt;
  
  
  Summary
&lt;/h2&gt;

&lt;p&gt;In short, the following three principles govern the entire working procedure of Redux&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The global state of an application is stored in an object tree within a single &lt;strong&gt;store&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;The only way to change the state is to emit an &lt;strong&gt;action&lt;/strong&gt;, which is an object describing what happened&lt;/li&gt;
&lt;li&gt;To specify how the state tree is transformed by actions, we write &lt;strong&gt;pure reducers&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In the next blog, I'll show how to get started with your first redux powered react application. Till then, stay tuned.&lt;/p&gt;

&lt;h2&gt;
  
  
  Wrapup
&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;Thanks for reading! I really hope you enjoyed reading about redux and its core principles and found this blog useful. Do consider hitting the like button and sharing it with your friends, I'd really appreciate that.  Stay tuned for more amazing content! Peace out! 🖖&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Social Links
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;LinkedIn : &lt;a href="https://www.linkedin.com/in/sohamderoy/" rel="noopener noreferrer"&gt;https://www.linkedin.com/in/sohamderoy/&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Website: &lt;a href="https://www.sohamderoy.dev/" rel="noopener noreferrer"&gt;https://www.sohamderoy.dev/&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>redux</category>
      <category>react</category>
      <category>javascript</category>
      <category>webdev</category>
    </item>
    <item>
      <title>How to Google like a Pro 😎. #10Tips</title>
      <dc:creator>Soham De Roy</dc:creator>
      <pubDate>Wed, 09 Feb 2022 18:27:55 +0000</pubDate>
      <link>https://dev.to/sohamderoy/how-to-google-like-a-pro-10tips-108h</link>
      <guid>https://dev.to/sohamderoy/how-to-google-like-a-pro-10tips-108h</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Everything is available on the internet and google is a platform to search through them. Well, everyone knows that ... &lt;em&gt;duhh&lt;/em&gt;. But how many of us know how to use google search &lt;strong&gt;efficiently&lt;/strong&gt;? Very few actually. &lt;strong&gt;Googling is an art&lt;/strong&gt;. To get the right answers, you need to ask the right questions, but to get the right answers quickly, you must know &lt;strong&gt;how&lt;/strong&gt; to ask the right questions. Everyone should learn the &lt;strong&gt;how&lt;/strong&gt; part, and that's what this blog is all about. Below are some of the great tips and tricks you can use to find correct answers to your questions effectively and efficiently.&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Using quotes to get the "EXACT" match
&lt;/h3&gt;

&lt;p&gt;Generally, when we do a normal search on Google, it makes a &lt;strong&gt;shallow&lt;/strong&gt; search which may result in pages that &lt;strong&gt;may or may not contain&lt;/strong&gt; all the words you mentioned in the search query. But if you wrap your search query/ question (either a term or a phrase) within quotes i.e. &lt;code&gt;"your question goes here"&lt;/code&gt; then Google will do a deep search and all the results &lt;strong&gt;will include&lt;/strong&gt; pages that &lt;strong&gt;contain all the terms&lt;/strong&gt; in your question that you put within quotes. This is helpful when you absolutely want a particular term/ phrase to be there in your search results&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%2Fv1643484565457%2FmJC6bxA5g.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%2Fv1643484565457%2FmJC6bxA5g.png" alt="img1.PNG"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Search within a specific site with &lt;code&gt;site:&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;If you want Google to return results from within a particular website, just add &lt;code&gt;site:&lt;/code&gt; before the question you are searching. This is also helpful when you want to search for something within a website which do not have an internal search option or perhaps have a bad one. For e.g. searching for &lt;strong&gt;&lt;em&gt;site:freecodecamp.org react&lt;/em&gt;&lt;/strong&gt; will populate search results only from &lt;a href="https://www.freecodecamp.org/" rel="noopener noreferrer"&gt;www.freecodecamp.org&lt;/a&gt; website on the topic of React.&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%2Fv1643484122371%2F8yE5PPStc.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%2Fv1643484122371%2F8yE5PPStc.png" alt="img2.PNG"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Excluding a term from search results with &lt;code&gt;-&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;If you don't want a term or phrase to appear in your search result, then just add &lt;code&gt;-&lt;/code&gt; in front of that word. For e.g. a search on =&amp;gt; &lt;strong&gt;&lt;em&gt;how to write components in React -class&lt;/em&gt;&lt;/strong&gt; will return all the search results that will not have the term "class" in them. Thus (if you know a bit of React) giving you only ways how to write functional components in React.&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%2Fv1643484833474%2FYgP0lXc3Z.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%2Fv1643484833474%2FYgP0lXc3Z.png" alt="img3.PNG"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  4. Search images of a particular size with &lt;code&gt;imagesize:&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;If you want to search images of a particular size then use the tag &lt;code&gt;imagesize:&lt;/code&gt; in your search query along with the width and height in &lt;strong&gt;pixels&lt;/strong&gt;. Dimension should be in &lt;strong&gt;pixels&lt;/strong&gt; only for e.g. &lt;code&gt;imagesize:500x500&lt;/code&gt; will populate image results which have a dimension of 500px x 500px&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%2Fv1643487619183%2FTQOAps79k.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%2Fv1643487619183%2FTQOAps79k.png" alt="img4.PNG"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  5. Searching for a particular filetype with &lt;code&gt;filetype:&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;If you want to get search results that contain a particular file type such as PDF or PPT etc, then add &lt;code&gt;filetype:&amp;lt;extension&amp;gt;&lt;/code&gt; (without the angular brackets). For eg: &lt;strong&gt;&lt;em&gt;react tutorial filetype:pdf&lt;/em&gt;&lt;/strong&gt; will generate the following results&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%2Fv1643483495682%2FF-BtFb-as.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%2Fv1643483495682%2FF-BtFb-as.png" alt="img5.PNG"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  6. Use wildcard &lt;code&gt;*&lt;/code&gt; to make searches
&lt;/h3&gt;

&lt;p&gt;If you are unsure about or have forgotten any term in your search query/ question, then use the wildcard &lt;code&gt;*&lt;/code&gt;, and Google will replace it for you with relevant terms. For e.g. a search on =&amp;gt; the * of money will populate the following results&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%2Fv1643485851556%2F4BBpNgKcm.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%2Fv1643485851556%2F4BBpNgKcm.png" alt="img6.PNG"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  7. Combining searches with &lt;code&gt;OR&lt;/code&gt;, &lt;code&gt;AND&lt;/code&gt; logic
&lt;/h3&gt;

&lt;p&gt;If you want your search results to contain two terms then put the &lt;code&gt;AND&lt;/code&gt; keyword in between them. For e.g. the search on =&amp;gt; &lt;strong&gt;&lt;em&gt;React AND Angular&lt;/em&gt;&lt;/strong&gt; will fetch results that have both the terms react and angular in it. Similarly, if you want either of the terms in your search results then use the &lt;code&gt;OR&lt;/code&gt; keyword in between them. For e.g. the search on =&amp;gt; &lt;strong&gt;&lt;em&gt;React OR Angular&lt;/em&gt;&lt;/strong&gt; will fetch results that have either of the terms or even both.&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%2Fv1643482858446%2FkiZMDKoFr.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%2Fv1643482858446%2FkiZMDKoFr.png" alt="img7.PNG"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  8. Filter out searches with &lt;code&gt;AFTER:&lt;/code&gt;, &lt;code&gt;BEFORE:&lt;/code&gt; or &lt;code&gt;..&lt;/code&gt; between two numbers
&lt;/h3&gt;

&lt;p&gt;If you want Google to populate search results that were published after a particular year then use the tag &lt;code&gt;AFTER:&lt;/code&gt;. For e.g. the search on =&amp;gt; &lt;strong&gt;&lt;em&gt;React tutorials AFTER:2020&lt;/em&gt;&lt;/strong&gt; will populate search results published after 2020. Similarly adding a tag &lt;code&gt;BEFORE:&lt;/code&gt; will return results published before a particular year. You can also search for results published between a certain year range or for that matter between any number. Just add &lt;code&gt;..&lt;/code&gt; between the two numbers you want to search between along with the units if any.&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%2Fv1643482600291%2FJVMpAHzF-.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%2Fv1643482600291%2FJVMpAHzF-.png" alt="img8.PNG"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  9. Check out related websites using &lt;code&gt;related:&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;If you want to know what all other websites are available on the internet which is similar to a particular website, then use the &lt;code&gt;related:&lt;/code&gt; tag. For e.g. a search on &lt;strong&gt;&lt;em&gt;related:google.com&lt;/em&gt;&lt;/strong&gt; will fetch all the websites that are similar to Google like Bing, Yahoo, DuckDuckGo etc.&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%2Fv1643482297259%2FkPv6sce9q.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%2Fv1643482297259%2FkPv6sce9q.png" alt="img9.PNG"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  10. To see Google's cached version of a website
&lt;/h3&gt;

&lt;p&gt;Google stores a cached version of websites to provide search results quickly. To see if google has cached any site or not just use the tag &lt;code&gt;cache:&lt;/code&gt; in front of the website's URL. This is especially helpful to &lt;strong&gt;web developers&lt;/strong&gt; to check if they are currently viewing a cached site or the latest version of a website after they have pushed some changes on the website. For e.g. a search for =&amp;gt; &lt;strong&gt;&lt;em&gt;cache:&lt;a href="http://www.sohamderoy.dev" rel="noopener noreferrer"&gt;www.sohamderoy.dev&lt;/a&gt;&lt;/em&gt;&lt;/strong&gt; on the day of writing this blog i.e. 30th Jan 2022 returns the following result.&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%2Fv1643483690495%2F7bmCTor_-.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%2Fv1643483690495%2F7bmCTor_-.png" alt="img10.PNG"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It is important to note that "Not all search operators return exhaustive results." as mentioned by &lt;a href="https://support.google.com/websearch/answer/2466433?visit_id=637790664879774647-1036329470&amp;amp;p=adv_pages_similar&amp;amp;hl=en&amp;amp;rd=1" rel="noopener noreferrer"&gt;Google&lt;/a&gt; itself. Still, I believe that these are some really handy tips that help a lot to make an effective and efficient Google search. I hope I was able to explain them properly and have encouraged you to use them in your regular Google search.&lt;/p&gt;

&lt;h2&gt;
  
  
  Wrapup
&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;Thanks for reading! If you like this blog and feel it's useful, do consider hitting the like button and sharing it with your friends, I'd really appreciate that. Stay tuned for more amazing content! 🖖&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.linkedin.com/in/sohamderoy/" rel="noopener noreferrer"&gt;&lt;strong&gt;Follow me on linkedin&lt;/strong&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>programming</category>
      <category>productivity</category>
      <category>developer</category>
    </item>
    <item>
      <title>Understanding Tailwind CSS</title>
      <dc:creator>Soham De Roy</dc:creator>
      <pubDate>Mon, 24 Jan 2022 14:14:57 +0000</pubDate>
      <link>https://dev.to/sohamderoy/understanding-tailwind-css-10k0</link>
      <guid>https://dev.to/sohamderoy/understanding-tailwind-css-10k0</guid>
      <description>&lt;p&gt;In this blog, we will try to understand comprehensively what is Tailwind CSS, what advantages it has to offer, along some hands-on code. 👨‍💻&lt;/p&gt;

&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Writing CSS can many times turn into a nightmare. Period. I get it. It gets very frustrating at times to nail down on those designs that you got from your design team. I'm sure a lot of developers, if not all, have gone through the same pain at least a few times in their development careers. Well not anymore. Coz it's time to learn an interesting piece of tech that takes a lot of burden from us. And no it's not Bootstrap. It's called Tailwind CSS. Well, I agree its been around for quite a while now, but I believe Tailwind CSS is still yet to reach out to a lot of developers out there who have not used it because:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;They haven't heard of it yet (which might be a very small number) or &lt;/li&gt;
&lt;li&gt;They don't really know whether learning a new piece of tech related to CSS will ease out their life or not. (well of course coz you know there have been a lot of things out there, vanilla CSS3, LESS, SCSS, Bootstrap, styled-components, Windi CSS and whatnot ... pheew... quite a list isn't it )&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--BjsGFuZg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1642961441083/mQi8Tyh-R.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--BjsGFuZg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1642961441083/mQi8Tyh-R.gif" alt="spongebob-long-list.gif" width="120" height="90"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I really hope this short guide will help you understand Tailwind CSS to a point that you say "This is it. This is the one".&lt;/p&gt;

&lt;p&gt;Well enough of chit chat. Let's dive straight in.&lt;/p&gt;

&lt;h2&gt;
  
  
  Atomic CSS approach
&lt;/h2&gt;

&lt;p&gt;Before jumping into Tailwind CSS, let's understand what Atomic CSS is. According to &lt;a href="https://css-tricks.com/lets-define-exactly-atomic-css/"&gt;CSS Tricks&lt;/a&gt; &lt;em&gt;"Atomic CSS is the approach to CSS architecture that favours small, single-purpose classes with names based on visual function."&lt;/em&gt; It's kinda like making classes that are supposed to achieve a single purpose. For e.g. let's make a &lt;code&gt;bg-blue&lt;/code&gt; class with the following CSS&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.bg-blue {
  background-color: rgb(81, 191, 255);
}

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

&lt;/div&gt;



&lt;p&gt;Now if we add this class to a &lt;code&gt;&amp;lt;h1&amp;gt;&lt;/code&gt; tag then it will get a background of blue with the colour being &lt;code&gt;rgb(81, 191, 255)&lt;/code&gt; as mentioned in the CSS.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;html lang="en"&amp;gt;
  &amp;lt;head&amp;gt;
    &amp;lt;meta charset="UTF-8" /&amp;gt;
    &amp;lt;meta http-equiv="X-UA-Compatible" content="IE=edge" /&amp;gt;
    &amp;lt;meta name="viewport" content="width=device-width, initial-scale=1.0" /&amp;gt;
    &amp;lt;title&amp;gt;Document&amp;lt;/title&amp;gt;
    &amp;lt;link rel="stylesheet" href="style.css" /&amp;gt;
  &amp;lt;/head&amp;gt;
  &amp;lt;body&amp;gt;
    &amp;lt;div&amp;gt;&amp;lt;h1 class="bg-blue"&amp;gt;Hello world!&amp;lt;/h1&amp;gt;&amp;lt;/div&amp;gt;
  &amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So the above HTML will result in something like this&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--4uzlt4u4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1642964574002/RbJnAg_vP.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--4uzlt4u4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1642964574002/RbJnAg_vP.png" alt="img2.PNG" width="880" height="160"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now imagine writing such useful &lt;strong&gt;single-purpose CSS rules&lt;/strong&gt; and keeping them all in a &lt;strong&gt;global CSS file&lt;/strong&gt;. I know it's a one-time investment but think of this, you can now use these single-purpose helper classes from anywhere you want. You just need your HTML file to consume that global CSS file and that's it. You can now also use combinations of these helper classes in a single HTML tag. Let's see another example shall we:&lt;/p&gt;

&lt;p&gt;Let's create a CSS file with the following rules,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.bg-blue {
  background-color: rgb(81, 191, 255);
}
.bg-green {
  background-color: rgb(81, 255, 90);
}
.text-underline {
  text-decoration: underline;
}
.text-center {
  text-align: center;
}
.font-weight-400 {
  font-weight: 400;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and then consume it in our HTML file as follows&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;html lang="en"&amp;gt;
  &amp;lt;head&amp;gt;
    &amp;lt;meta charset="UTF-8" /&amp;gt;
    &amp;lt;meta http-equiv="X-UA-Compatible" content="IE=edge" /&amp;gt;
    &amp;lt;meta name="viewport" content="width=device-width, initial-scale=1.0" /&amp;gt;
    &amp;lt;title&amp;gt;Document&amp;lt;/title&amp;gt;
    &amp;lt;link rel="stylesheet" href="style.css" /&amp;gt;
  &amp;lt;/head&amp;gt;
  &amp;lt;body&amp;gt;
    &amp;lt;div&amp;gt;&amp;lt;h1 class="bg-blue"&amp;gt;Hello world 1&amp;lt;/h1&amp;gt;&amp;lt;/div&amp;gt;
    &amp;lt;div&amp;gt;&amp;lt;h1 class="text-underline"&amp;gt;Hello world 2&amp;lt;/h1&amp;gt;&amp;lt;/div&amp;gt;
    &amp;lt;div class="text-center"&amp;gt;
      &amp;lt;h1 class="bg-green font-weight-400 text-underline"&amp;gt;Hello world 3&amp;lt;/h1&amp;gt;
    &amp;lt;/div&amp;gt;
  &amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Well now this will generate the following result:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--to3PTxW---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1642964648678/CLDvFnzhU.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--to3PTxW---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1642964648678/CLDvFnzhU.png" alt="img3.PNG" width="880" height="214"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;🗒️ Points to note here:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Combining multiple helper classes:&lt;/strong&gt; Look how I have combined multiple helper classes in line 14 in the &lt;code&gt;&amp;lt;h1&amp;gt;&lt;/code&gt; tag viz. &lt;code&gt;bg-green&lt;/code&gt;, &lt;code&gt;font-weight-400&lt;/code&gt; and &lt;code&gt;text-underline&lt;/code&gt; and it all took effect in my &lt;strong&gt;Hello world 3&lt;/strong&gt; text&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Reusability of helper classes:&lt;/strong&gt; In the above example look at how &lt;code&gt;text-underline&lt;/code&gt; helper class is used multiple times in lines 12 and 14.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;See how we were able to add different styles without even leaving the HTML page. Well, you would say that, &lt;em&gt;"Hey we did have to write those helper or utility classes in the global CSS file... what about that"&lt;/em&gt;. Well, I get it. That definitely was the initial investment we had to make to start with. And of course, God knows how many of these single-purpose helper or utility classes we would have to make if we wanted to follow this &lt;em&gt;Atomic CSS&lt;/em&gt; architecture. And that's where &lt;strong&gt;Tailwind CSS comes as our saviour&lt;/strong&gt;. (Well more than a saviour if I may .. continue reading to know more). The concept of Atomic CSS is not new but Tailwind CSS takes it to another level.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Sgjxlxlh--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1642963746441/Hg5-_aF-F.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Sgjxlxlh--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1642963746441/Hg5-_aF-F.jpeg" alt="saviour.jpg" width="259" height="194"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Tailwind CSS - A utility first CSS framework
&lt;/h2&gt;

&lt;p&gt;Tailwind CSS, as per their own &lt;a href="https://tailwindcss.com/"&gt;website&lt;/a&gt; is a "&lt;strong&gt;utility-first CSS framework&lt;/strong&gt;" which provides several of these &lt;strong&gt;&lt;em&gt;opinionated&lt;/em&gt;&lt;/strong&gt;, &lt;strong&gt;&lt;em&gt;single-purpose&lt;/em&gt;&lt;/strong&gt; &lt;strong&gt;&lt;em&gt;utility classes&lt;/em&gt;&lt;/strong&gt; that can be directly used inside our markup to design an element. Some of the utility classes that I frequently use these days are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;flex&lt;/strong&gt;: Used to apply flexbox to a &lt;code&gt;&amp;lt;div&amp;gt;&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;items-center&lt;/strong&gt;: to apply the CSS property &lt;code&gt;align-items: center;&lt;/code&gt; to a &lt;code&gt;&amp;lt;div&amp;gt;&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;rounded-full&lt;/strong&gt;: to make an image circular and so on ... &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Seriously, it's not possible for me to list down all of them coz there are so many of these utility classes. But the best part is, we do not have to write these utility classes ourselves and keep in any global CSS file. We directly get it from Tailwind. You can get a list of all the utility classes they have to offer from their &lt;a href="https://tailwindcss.com/docs/installation"&gt;documentation page&lt;/a&gt;. Also if you are working in VS Code, you can install an extension called &lt;a href="https://marketplace.visualstudio.com/items?itemName=bradlc.vscode-tailwindcss"&gt;Tailwind CSS IntelliSense&lt;/a&gt; and it will give you auto-suggestions as you keep typing the utility classes as shown in the image below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--u30onloy--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1642964690968/W1nISvuyg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--u30onloy--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1642964690968/W1nISvuyg.png" alt="img4.PNG" width="880" height="273"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Setting up Tailwind CSS
&lt;/h3&gt;

&lt;p&gt;There are multiple ways by which we can set up Tailwind CSS in our project all of which are mentioned in their &lt;a href="https://tailwindcss.com/docs/installation"&gt;documentation&lt;/a&gt;. Tailwind CSS works smoothly with a plethora of frameworks like Next, React, Angular etc. and even our OG HTML. &lt;/p&gt;

&lt;p&gt;For the below hands-on demo I am using &lt;strong&gt;Tailwind CSS with a Next application&lt;/strong&gt;. To set a Next app with Tailwind CSS directly, use the following command:&lt;/p&gt;

&lt;p&gt;With &lt;code&gt;npx&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;npx create-next-app --example with-tailwindcss with-tailwindcss-app
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;or with &lt;code&gt;yarn&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;yarn create next-app --example with-tailwindcss with-tailwindcss-app
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once the project has been set up dive into the next step to create a basic card component &lt;/p&gt;

&lt;h3&gt;
  
  
  Hands-on demo
&lt;/h3&gt;

&lt;p&gt;Let's build a card component in a Next project&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Card.js file
// to be rendered in index.js

import React from "react";

const Card = () =&amp;gt; {
  return (
    &amp;lt;div className="relative w-96 m-3 cursor-pointer border-2 shadow-lg rounded-xl items-center"&amp;gt;
      {/* Image */}
      &amp;lt;div className="flex h-28 bg-blue-700 rounded-xl items-center justify-center"&amp;gt;
        &amp;lt;h1 className="absolute mx-auto text-center right text-2xl text-white"&amp;gt;
          Image goes here
        &amp;lt;/h1&amp;gt;
      &amp;lt;/div&amp;gt;

      {/* Description */}
      &amp;lt;div className="p-2 border-b-2"&amp;gt;
        &amp;lt;h6&amp;gt;
          Lorem ipsum dolor sit amet consectetur adipisicing elit. Facilis
          beatae nulla, atque et sunt ad voluptatum quidem impedit numquam quia?
          Lorem ipsum dolor sit amet consectetur adipisicing elit. Facilis
          beatae nulla, atque et sunt ad voluptatum quidem impedit numquam quia?
        &amp;lt;/h6&amp;gt;
      &amp;lt;/div&amp;gt;

      {/* Tech stack used */}
      &amp;lt;div className="flex flex-wrap items-center m-2"&amp;gt;
        &amp;lt;span className=" border border-blue-300 rounded-2xl px-2 my-1 mx-1"&amp;gt;
          #React
        &amp;lt;/span&amp;gt;
        &amp;lt;span className=" border border-blue-300 rounded-2xl px-2 my-1 mx-1"&amp;gt;
          #Redux
        &amp;lt;/span&amp;gt;
        &amp;lt;span className=" border border-blue-300 rounded-2xl px-2 my-1 mx-1"&amp;gt;
          #Javascript
        &amp;lt;/span&amp;gt;
      &amp;lt;/div&amp;gt;

      {/* Links */}
      &amp;lt;div className="flex flex-wrap items-center rounded-b-xl border-t-2 bg-white"&amp;gt;
        &amp;lt;button className="border rounded-2xl bg-blue-600 text-white shadow-sm p-1 px-2 m-2"&amp;gt;
          Go to Project
        &amp;lt;/button&amp;gt;
        &amp;lt;button className="border-2 border-blue-600 rounded-2xl text-blue-600 shadow-sm p-1 px-2 m-2"&amp;gt;
          Github
        &amp;lt;/button&amp;gt;
      &amp;lt;/div&amp;gt;
    &amp;lt;/div&amp;gt;
  );
};

export default Card;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This results in the following card to be rendered in the UI:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--gJg-mcFL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1642957964214/N9OQWmqky.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--gJg-mcFL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1642957964214/N9OQWmqky.png" alt="img5.PNG" width="519" height="517"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Look how easily I am able to style the card component without even leaving the Card.js file. No need to write any extra CSS files. Using &lt;code&gt;flex&lt;/code&gt; to a &lt;code&gt;&amp;lt;div&amp;gt;&lt;/code&gt; applies &lt;code&gt;display: flex;&lt;/code&gt; CSS rule to it. Want to add &lt;code&gt;position: relative;&lt;/code&gt; to a &lt;code&gt;&amp;lt;div&amp;gt;&lt;/code&gt;? Just add &lt;code&gt;relative&lt;/code&gt; in the &lt;code&gt;className&lt;/code&gt; and you are done.  We can also add different modifiers like &lt;code&gt;hover&lt;/code&gt;, &lt;code&gt;active&lt;/code&gt;, &lt;code&gt;focus&lt;/code&gt; etc. to conditional render utility classes. It is possible to apply complex CSS rules like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.some-class-name {
          --tw-space-x-reverse: 0;
          margin-right: calc(0.5rem * var(--tw-space-x-reverse));
          margin-left: calc(0.5rem * calc(1 - var(--tw-space-x-reverse)));
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;by just mentioning &lt;code&gt;space-x-2&lt;/code&gt; in the &lt;code&gt;&amp;lt;div&amp;gt;&lt;/code&gt; tag. Neat isn't it. And do we have to mention these styles explicitly anywhere in some sort of a global CSS file... &lt;strong&gt;absolutely not!&lt;/strong&gt;. Tailwind automagically does it for us. That's the beauty of Tailwind.&lt;/p&gt;

&lt;h3&gt;
  
  
  We are not done yet... there's a lot of other advantages
&lt;/h3&gt;

&lt;h4&gt;
  
  
  Just-In-Time (JIT) mode -- providing lightning-fast build times
&lt;/h4&gt;

&lt;p&gt;Prior to Tailwind v3, it used to purge through all the styles to remove any unused styles, so that the production build remains as small as possible. According to Tailwind, the production build used to be between 5 - 10 kB. But that's the story in production. In a development environment, CSS might get really big especially if we use a lot of personalized configuration.&lt;/p&gt;

&lt;p&gt;With v3 and above, Tailwind released a new feature called &lt;strong&gt;Just-in-Time compiler&lt;/strong&gt;. JIT compiler avoids compiling all the CSS upfront and compiles only the CSS as and when we need it. This results in &lt;strong&gt;lightning-fast build times&lt;/strong&gt; in all the environments. And as the styles are generated as and when we need them, there is no need to purge unused styles and thus CSS is &lt;strong&gt;all the environments will be the same&lt;/strong&gt;. This helps us get rid of the fear of any important CSS getting purged in production.&lt;/p&gt;

&lt;p&gt;Watch &lt;a href="https://twitter.com/adamwathan"&gt;Adam Wathan&lt;/a&gt; the creator of Tailwind CSS explaining JIT in Tailwind Labs official youtube channel:&lt;/p&gt;

&lt;h4&gt;
  
  
  Opinionated and flexible at the same time
&lt;/h4&gt;

&lt;p&gt;Tailwind CSS is opinionated. It does specify some constraints when it comes to styling and if you ask me it is good as it helps us keep the design part to those who actually understand it. Just look at one of their utility classes to add &lt;code&gt;box-shadow&lt;/code&gt; to your &lt;code&gt;&amp;lt;div&amp;gt;&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--n5odYuI5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1642957329818/SHly5x3UM.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--n5odYuI5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1642957329818/SHly5x3UM.png" alt="img6.PNG" width="654" height="338"&gt;&lt;/a&gt;&lt;br&gt;
(src: &lt;a href="https://tailwindcss.com/docs/box-shadow"&gt;https://tailwindcss.com/docs/box-shadow&lt;/a&gt;)&lt;/p&gt;

&lt;p&gt;As you can see, there are only 8 variants of shadow that Tailwind provides, with a preset value for vertical and horizontal offset, blur, spread, colour and opacity. That is why Tailwind is opinionated. It tries to give an opinion about what property values to choose from on almost all the styling properties out there. And believe me, for most of the cases, these 8 variants (for &lt;code&gt;box-shadow&lt;/code&gt;) will be more than sufficient to come up with a great UI. For e.g. in the above hands-on example, I have used &lt;code&gt;shadow-lg&lt;/code&gt; in the main parent &lt;code&gt;&amp;lt;div&amp;gt;&lt;/code&gt; to get that nice outer box-shadow. Using the same variant of a particular utility class at different areas in the UI  also ensures uniformity across the whole application and thus a better UX.&lt;/p&gt;

&lt;p&gt;But in case you need some really customised value for any particular style, you can do so by adding a customized theme in the &lt;code&gt;tailwind.config.js&lt;/code&gt;. For e.g. to get a &lt;code&gt;shadow-3xl&lt;/code&gt; (Tailwind do not provide &lt;code&gt;shadow-3xl&lt;/code&gt; out of the box) you can add the following lines in the &lt;code&gt;module.exports&lt;/code&gt; in &lt;code&gt;tailwind.config.js&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;module.exports = {
  theme: {
    extend: {
      boxShadow: {
        '3xl': '0 35px 60px -15px rgba(0, 0, 0, 0.3)',
      }
    }
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And now with the advent of &lt;strong&gt;JIT&lt;/strong&gt;, you can also use an arbitrary value inside a square bracket &lt;code&gt;[]&lt;/code&gt; like 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;&amp;lt;div class="shadow-[0_35px_60px_-15px_rgba(0,0,0,0.3)]"&amp;gt;
  // Rest of your code goes here
&amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Using arbitrary values may be useful when you need a specific style at only a few places for which creating a theme for it in the &lt;code&gt;tailwind.config.js&lt;/code&gt; might seem to be unnecessary.&lt;/p&gt;

&lt;h2&gt;
  
  
  My thoughts
&lt;/h2&gt;

&lt;p&gt;I really hope that I was able to make you understand what Tailwind CSS is and what can be achieved with it. It is a CSS framework that provides us with &lt;strong&gt;single-purpose utility classes&lt;/strong&gt; which are &lt;strong&gt;opinionated&lt;/strong&gt; for the most part, and which help us design our web pages from right inside our &lt;em&gt;markup&lt;/em&gt; or &lt;em&gt;.js/.jsx/.ts/.tsx files&lt;/em&gt;. In my opinion, it's &lt;strong&gt;simple&lt;/strong&gt; and &lt;strong&gt;easy to understand&lt;/strong&gt;. It's true that it might take some time to get hang of all the utility class names. Do refer to their documentation whenever you get stuck. And to all the beginners out there who are just starting their journey with web development, it is very important to know what CSS3 is before you even explore Tailwind or for that matter any other CSS framework like Bootstrap, Windi CSS etc. &lt;/p&gt;

&lt;p&gt;&lt;em&gt;Thanks for reading! If you like this blog and feel it's useful, do consider hitting the like button and sharing it with your friends, I'd really appreciate that. Stay tuned for more amazing content! 🖖&lt;/em&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>tailwindcss</category>
      <category>css</category>
    </item>
    <item>
      <title>Important GIT commands you'll need to know 🔥 [Part 2] (for the major part of your work)</title>
      <dc:creator>Soham De Roy</dc:creator>
      <pubDate>Thu, 12 Aug 2021 11:10:09 +0000</pubDate>
      <link>https://dev.to/sohamderoy/important-git-commands-you-ll-need-to-know-part-2-for-the-major-part-of-your-work-2epg</link>
      <guid>https://dev.to/sohamderoy/important-git-commands-you-ll-need-to-know-part-2-for-the-major-part-of-your-work-2epg</guid>
      <description>&lt;h1&gt;
  
  
  📋 Summary
&lt;/h1&gt;

&lt;p&gt;In this part, we will cover the following commands ⬇️⬇️⬇️&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;git clone &amp;lt;Remote_URL&amp;gt;&lt;/code&gt;: To clone the remote repo to your local machine.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;git checkout -b &amp;lt;Branch_Name&amp;gt; origin/&amp;lt;Branch_Name&amp;gt;&lt;/code&gt;: This will create a new local branch named &lt;strong&gt;&lt;em&gt;"Branch_Name"&lt;/em&gt;&lt;/strong&gt; AND will also set it to track the remote copy of the branch &lt;strong&gt;&lt;em&gt;"origin/Branch_Name"&lt;/em&gt;&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;git fetch&lt;/code&gt;: It will fetch the changes from the remote and put them in our local repo. It will &lt;strong&gt;not&lt;/strong&gt; make the changes &lt;strong&gt;visible in the working directory&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;git merge&lt;/code&gt;: Will automatically merge those differences to the working directory.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;git pull&lt;/code&gt; = &lt;code&gt;git fetch&lt;/code&gt; + &lt;code&gt;git merge&lt;/code&gt;: It will fetch all the changes in remote and directly merge them to the working directory.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;git stash&lt;/code&gt;: Stash up changes in files that are currently tracked by git at some other place. It will not stash changes in untracked and ignored files.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;git stash -u&lt;/code&gt;: This allows us to stash even untracked files but not ignored files.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;git stash -a&lt;/code&gt;: Allows us to stash all types of files tracked, untracked and ignored.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;git stash list&lt;/code&gt;: List down all the entries in the stash.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;git stash pop&lt;/code&gt;: Removes the latest stash &lt;strong&gt;&lt;em&gt;(stash@{0})&lt;/em&gt;&lt;/strong&gt; from the list and applies it to the working tree.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;git stash apply&lt;/code&gt;: Applies the latest stash &lt;strong&gt;&lt;em&gt;(stash@{0})&lt;/em&gt;&lt;/strong&gt; from the list to the working tree and keep it in the stash list.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;git stash pop stash@{2}&lt;/code&gt;/ &lt;code&gt;git stash apply stash@{2}&lt;/code&gt;: Applies the 2nd stash &lt;strong&gt;&lt;em&gt;(stash@{2})&lt;/em&gt;&lt;/strong&gt; from the list to the working tree and deletes it/ keep it in the stash list respectively.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--L6k-uhxl--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1628185209748/CG0yIf8bW.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--L6k-uhxl--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1628185209748/CG0yIf8bW.png" alt="Picture15.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Hello world 🖖. Welcome to the second part of the blog on &lt;strong&gt;Important GIT commands you'll need to know&lt;/strong&gt;. The first part mainly covers the set of commands which are required probably when you are working alone on a project. It focuses mainly on the following points&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Initialise a git local repo&lt;/li&gt;
&lt;li&gt;Check which files you have made changes in &lt;/li&gt;
&lt;li&gt;Add those files to the staging area and commit them to a branch &lt;/li&gt;
&lt;li&gt;Create separate branches for separate features and checkout code in different branches&lt;/li&gt;
&lt;li&gt;And finally to push your code to a remote repository so that others can also see/ contribute to your code.
If you haven't read the first part of this blog, do check it out here  &lt;a href="https://dev.to/sohamderoy/important-git-commands-you-ll-need-to-know-part-1-for-the-major-part-of-your-work-139e"&gt;Important GIT commands you'll need to know 🔥 [Part 1]&lt;/a&gt;  before moving forward to get a better perspective.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;As you might remember that in the first part we discussed two possibilities viz.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;em&gt;You want to start a new project&lt;/em&gt;&lt;/strong&gt; (covered in  &lt;a href="https://dev.to/sohamderoy/important-git-commands-you-ll-need-to-know-part-1-for-the-major-part-of-your-work-139e"&gt;Part 1&lt;/a&gt;) and &lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;em&gt;You want to contribute to an existing code base&lt;/em&gt;&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This part of the blog will cover the &lt;strong&gt;second scenario&lt;/strong&gt; in depth. So let's get started...&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--rzNbccBr--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1628534830726/ldCoTKMHD.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--rzNbccBr--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1628534830726/ldCoTKMHD.gif" alt="giphy.gif"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  How to get the codebase from the remote repo to my local machine? - git clone 👨‍💻
&lt;/h1&gt;

&lt;p&gt;Suppose you want to contribute to a project. For that, you want to know that where the codebase is located. For this case, we are assuming that it's in a remote repo in Github. As you remember that we created a remote github repo in &lt;a href="https://dev.to/sohamderoy/important-git-commands-you-ll-need-to-know-part-1-for-the-major-part-of-your-work-139e"&gt;Part 1&lt;/a&gt; of the blog. We will try to clone that repo in our local machine by using the following steps. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--dEEK_y0Z--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1628185952367/IbKXH9Fpe.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--dEEK_y0Z--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1628185952367/IbKXH9Fpe.png" alt="Picture6.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Navigate to the remote repo (&lt;a href="https://github.com/sohamderoy/demo-repo"&gt;https://github.com/sohamderoy/demo-repo&lt;/a&gt; for this example) and copy the repo link under &lt;strong&gt;HTTPS&lt;/strong&gt; section as shown in the figure above.&lt;/li&gt;
&lt;li&gt;Navigate to a new folder you want to clone the project and open the git bash terminal.&lt;/li&gt;
&lt;li&gt;Execute command &lt;code&gt;git clone &amp;lt;Remote_URL&amp;gt;&lt;/code&gt; or in this case &lt;code&gt;git clone https://github.com/sohamderoy/demo-repo.git&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;After successful cloning, you'll see the following screen&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--qj6ljXhQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1628537780327/o8oaLdYs8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--qj6ljXhQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1628537780327/o8oaLdYs8.png" alt="14a.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The remote repo will get cloned in your folder and you'll be able to see the content of the remote repo in your machine. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Do note that&lt;/strong&gt; 👆&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;By default, after cloning the repo, you'll see the content of the &lt;strong&gt;main&lt;/strong&gt; branch. To see the content of any other branch do &lt;code&gt;git checkout &amp;lt;branch_name&amp;gt;&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;The cloned repo will already be initialized with git (you can see the &lt;strong&gt;.git&lt;/strong&gt; folder has already been created) and we don't have to run the &lt;code&gt;git init&lt;/code&gt; command. So this local repo will automatically start tracking any changes done to files within it.&lt;/li&gt;
&lt;li&gt;To check all the branch(es) linked to this repo, run command &lt;code&gt;git branch -a&lt;/code&gt;, and to check out any other branch run command &lt;code&gt;git checkout &amp;lt;branch_name&amp;gt;&lt;/code&gt;. For all other important commands on branching and pushing your changes to the remote repo please refer to &lt;a href="https://dev.to/sohamderoy/important-git-commands-you-ll-need-to-know-part-1-for-the-major-part-of-your-work-139e"&gt;Part 1&lt;/a&gt; of this blog.&lt;/li&gt;
&lt;li&gt;Also in this case where you have cloned a remote repo, you don't have to run the command &lt;code&gt;git remote add &amp;lt;remote_repo_URL&amp;gt;&lt;/code&gt;, as this time the cloned repo is already connected to a remote repo. Directly running &lt;code&gt;git remote -v&lt;/code&gt; will show the &lt;strong&gt;push&lt;/strong&gt; and &lt;strong&gt;fetch&lt;/strong&gt; URL set to the cloned repo. See image below&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--eI8FZRyQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1628532313982/lq09at3S4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--eI8FZRyQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1628532313982/lq09at3S4.png" alt="1a.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Before we move forward, I think it's high time that we need to clear a concept about how many different levels are there &lt;strong&gt;in between our working directory and the remote repo&lt;/strong&gt;. The following section explains&lt;/p&gt;

&lt;h1&gt;
  
  
  Working directory, Staging area, Local repo, Remote repo: Explained 👨‍🏫
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--aUmfiXn_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1628528296281/wUZsTXhwB.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--aUmfiXn_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1628528296281/wUZsTXhwB.png" alt="Picture2.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The above image is a very important one that helps to explain the different layers in the original version controlling process. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The working directory represents the state of files when we edit them. It is the state until we add it to the staging area. &lt;/li&gt;
&lt;li&gt;When we are a bit sure about the changes we made in the files, and we want to commit them to the branch, we add them to the staging area by doing &lt;code&gt;git add .&lt;/code&gt; or &lt;code&gt;git add &amp;lt;file_name&amp;gt;&lt;/code&gt; and do a &lt;code&gt;git commit -m "Commit message"&lt;/code&gt; to commit it to the local branch.&lt;/li&gt;
&lt;li&gt;To get these commits to the remote repo we run the command &lt;code&gt;git push&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now, this was the part that we have learnt till now (including the &lt;a href="https://dev.to/sohamderoy/important-git-commands-you-ll-need-to-know-part-1-for-the-major-part-of-your-work-139e"&gt;Part 1&lt;/a&gt; of this blog) i.e. the &lt;strong&gt;journey from the working directory to remote&lt;/strong&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Journey from Remote repo to Local repo and working directory. 🛣️
&lt;/h2&gt;

&lt;p&gt;Let's suppose that a co-contributor of your project has made some changes and pushed it to the remote. Let's try to simulate that. Remember our Github repo, in the &lt;strong&gt;&lt;em&gt;"new-branch"&lt;/em&gt;&lt;/strong&gt; branch of that remote repo, we have a file &lt;strong&gt;&lt;em&gt;"new.txt"&lt;/em&gt;&lt;/strong&gt; with contents as shown below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--69QvQmoS--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1628528686522/Cj1796vUc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--69QvQmoS--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1628528686522/Cj1796vUc.png" alt="2a.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We have already cloned this repo in our local so let's check out this new branch using the command &lt;code&gt;git checkout -b new-branch origin/new-branch&lt;/code&gt;. This will create a new local branch named &lt;strong&gt;&lt;em&gt;"new-branch"&lt;/em&gt;&lt;/strong&gt; AND will also set it to track the remote copy of the branch &lt;strong&gt;&lt;em&gt;"origin/new-branch"&lt;/em&gt;&lt;/strong&gt;. Note 👆, we can also use &lt;code&gt;git checkout new-branch&lt;/code&gt;, but that just create a new branch but will not track the remote branch. It will only do so if we push some changes in this branch to the remote using &lt;code&gt;git push -u origin new-branch&lt;/code&gt;. But as of now, we do not have anything to push so we use &lt;code&gt;git checkout -b new-branch origin/new-branch&lt;/code&gt; directly to create a new branch and track to the origin branch. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--OhJ2ueXz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1628528920592/G0aFbds5u.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--OhJ2ueXz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1628528920592/G0aFbds5u.png" alt="3a.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now that it's clear let's make some changes in the remote repo directly via Github and commit it as shown in the image below &lt;em&gt;(this is to &lt;strong&gt;simulate&lt;/strong&gt; the process where someone else is contributing to our project)&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Qxk6eU7W--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1628533154491/b4p_2PTsQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Qxk6eU7W--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1628533154491/b4p_2PTsQ.png" alt="4a.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To get these changes done by someone else in our local, we can use the following&lt;/p&gt;

&lt;h3&gt;
  
  
  git fetch (Remote repo to Local repo)
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;git fetch&lt;/code&gt; will fetch the changes from the remote and put them in our local repo. It will not make the changes visible in the working directory. Let's see how it works&lt;/p&gt;

&lt;p&gt;We are in the &lt;strong&gt;new-branch&lt;/strong&gt; branch in local. Let's run &lt;code&gt;git fetch&lt;/code&gt;. It shows that all changes from the remote branch are added in &lt;strong&gt;origin/new-branch&lt;/strong&gt; as shown in the image below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--kEbJLun_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1628533203129/R8p7g-gdf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--kEbJLun_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1628533203129/R8p7g-gdf.png" alt="5a.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;While remaining in &lt;strong&gt;new-branch&lt;/strong&gt; branch if we open &lt;strong&gt;"new.txt"&lt;/strong&gt; (i.e. the one in the working directory), &lt;strong&gt;it will not show us the changes done in Github&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--hsPXYEQn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1628533424102/KkmHRpr3e.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--hsPXYEQn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1628533424102/KkmHRpr3e.png" alt="6a.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;On the other hand if we checkout to &lt;strong&gt;"origin/new-branch"&lt;/strong&gt; and open "new.txt" (i.e. the one in the copy of the remote "new-branch" branch), &lt;strong&gt;it will show us the changes done in Github&lt;/strong&gt;. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--y9qZ-PUr--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1628533456197/b6baZqwXm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--y9qZ-PUr--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1628533456197/b6baZqwXm.png" alt="7a.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  git merge (Local repo to Working directory)
&lt;/h3&gt;

&lt;p&gt;If we want to see the difference between &lt;strong&gt;new-branch&lt;/strong&gt; and &lt;strong&gt;origin/new-branch&lt;/strong&gt; using the command &lt;code&gt;git diff new-branch origin/new-branch&lt;/code&gt; then it will show us the following difference.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--RJJHYAhy--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1628533509255/vPptEasO-.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--RJJHYAhy--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1628533509255/vPptEasO-.png" alt="8a.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now to get these changes merged to the local branch of &lt;strong&gt;"new-branch"&lt;/strong&gt; and get them reflected in files in working directory, we just need to run the command &lt;code&gt;git merge&lt;/code&gt;. As the branch &lt;strong&gt;"new-branch"&lt;/strong&gt; is tracking &lt;strong&gt;"origin/new-branch"&lt;/strong&gt;, &lt;code&gt;git merge&lt;/code&gt; will automatically merge those differences to the working directory. Now all the changes will be reflected in the working directory as shown in the image below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--J97Z1_Qd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1628533539845/l9vOyZjJg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--J97Z1_Qd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1628533539845/l9vOyZjJg.png" alt="9a.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  git pull (Directly from Remote repo to Working directory)
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;git pull&lt;/code&gt; is a shortcut to do &lt;code&gt;git fetch&lt;/code&gt; and &lt;code&gt;git merge&lt;/code&gt; is one go. It will thus download all the changes from the remote repo, and merge them directly to the local repo and working directory. So just remember the following&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--3TlL53nU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1628533571602/Vp865zWip.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--3TlL53nU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1628533571602/Vp865zWip.png" alt="Picture3.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let's say we again make some more changes in &lt;strong&gt;"new.txt"&lt;/strong&gt; directly via &lt;strong&gt;Github&lt;/strong&gt; and commit it. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--kPSt9AWI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1628533603422/cN02DEfqI.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--kPSt9AWI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1628533603422/cN02DEfqI.png" alt="10a.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now in local if we do a &lt;code&gt;git pull&lt;/code&gt;, it will download all the changes and put them in both &lt;strong&gt;"origin/new-branch"&lt;/strong&gt; and in &lt;strong&gt;"new-branch"&lt;/strong&gt; (i.e. all changes will be directly merged to the working directory). &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--S0yaKqia--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1628533637471/m3wcxketS.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--S0yaKqia--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1628533637471/m3wcxketS.png" alt="11a.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Running &lt;code&gt;git diff new-branch origin/new-branch&lt;/code&gt; will thus show no results as seen below&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--I39qpV9D--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1628533683284/gRowp90AH-.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--I39qpV9D--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1628533683284/gRowp90AH-.png" alt="12a.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  How to "Stash up" some of my recent changes for the time being so that I get to keep those changes somewhere without committing it? 📦
&lt;/h2&gt;

&lt;p&gt;In case you are working on some files, made some changes but also at the same time want to check out some different branch, git provides us with an option to stash up/ keep those current changes in some other place. We can achieve this by following:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;git stash&lt;/code&gt; : Stash up changes in files that are currently tracked by git at some other place. Thus your file needs to be added at least once for it to be considered for getting stashed. &lt;/li&gt;
&lt;li&gt;By default, we cannot stash any files that are in the &lt;strong&gt;"Untracked files"&lt;/strong&gt; section or files mentioned in &lt;em&gt;.gitignore&lt;/em&gt; file. For e.g. as per the image below, &lt;strong&gt;new.txt&lt;/strong&gt; was modified and added in the &lt;strong&gt;staging area&lt;/strong&gt; whereas &lt;strong&gt;newfile.docs&lt;/strong&gt; is a new file that's created and is still in the &lt;strong&gt;"Untracked files"&lt;/strong&gt; section. Running &lt;code&gt;git stash&lt;/code&gt; thus added only &lt;strong&gt;new.txt&lt;/strong&gt; in the stash.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--MUAinbmu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1628533712491/BvSP03liU.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--MUAinbmu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1628533712491/BvSP03liU.png" alt="13a.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;git stash -u&lt;/code&gt; : This allows us to stash even untracked files but not ignored files.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;git stash -a&lt;/code&gt; : Allows us to stash all types of files tracked, untracked and ignored.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;git stash list&lt;/code&gt; : List down all the entries in the stash.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;git stash pop&lt;/code&gt; : Removes the latest stash &lt;strong&gt;&lt;em&gt;(stash@{0})&lt;/em&gt;&lt;/strong&gt; from the list and applies it to the working tree.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;git stash apply&lt;/code&gt; : Applies the latest stash &lt;strong&gt;&lt;em&gt;(stash@{0})&lt;/em&gt;&lt;/strong&gt; from the list to the working tree and keep it in the stash list.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;git stash pop stash@{2}&lt;/code&gt;/ &lt;code&gt;git stash apply stash@{2}&lt;/code&gt; : Applies the 2nd stash &lt;strong&gt;&lt;em&gt;(stash@{2})&lt;/em&gt;&lt;/strong&gt; from the list to the working tree and deletes it/ keep it in the stash list respectively.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--BG5Ne-NF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1628533894751/GrayPCfJI.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--BG5Ne-NF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1628533894751/GrayPCfJI.gif" alt="e2bd7ce3fc5f2783f1e210b015cc5fb1.gif"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This marks the end of this blog. Don't get me wrong, this (i.e. the content covered in &lt;a href="https://dev.to/sohamderoy/important-git-commands-you-ll-need-to-know-part-1-for-the-major-part-of-your-work-139e"&gt;Part 1&lt;/a&gt; and Part 2) is &lt;strong&gt;not all of git&lt;/strong&gt;. It can never be. I will be releasing some more blogs in the future related to other commands in git. But the content covered in both these parts will help you &lt;strong&gt;sail through 99% of your daily task&lt;/strong&gt;. That was my main motive for these two parts. There are some more important commands in git, but those are not used that often when compared to the ones mentioned in both these parts. Don't worry, I'll soon gonna cover them separately.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;I hope that the content provided in both these parts will be helpful to all the readers. Thanks for reading! If you like this blog and feel it's useful, do consider hitting the link button and share it with your friends, I'd really appreciate that. Stay tuned! 🖖&lt;/em&gt;&lt;/p&gt;

</description>
      <category>git</category>
      <category>bash</category>
      <category>github</category>
      <category>programming</category>
    </item>
    <item>
      <title>Important GIT commands you'll need to know 🔥 [Part 1] (for the major part of your work)</title>
      <dc:creator>Soham De Roy</dc:creator>
      <pubDate>Mon, 02 Aug 2021 18:03:37 +0000</pubDate>
      <link>https://dev.to/sohamderoy/important-git-commands-you-ll-need-to-know-part-1-for-the-major-part-of-your-work-139e</link>
      <guid>https://dev.to/sohamderoy/important-git-commands-you-ll-need-to-know-part-1-for-the-major-part-of-your-work-139e</guid>
      <description>&lt;p&gt;👆&lt;strong&gt;&lt;em&gt;NOTE:&lt;/em&gt;&lt;/strong&gt; &lt;em&gt;This blog will be a bit longer as I will be explaining all the commands. Thus I will divide the blog into &lt;strong&gt;two parts&lt;/strong&gt; (this being the first one). I will update this part with a link to part 2 once I publish it. Both parts will also contain a &lt;strong&gt;summary&lt;/strong&gt; which will contain a list of all the commands mentioned in the blog for a quick revision.&lt;/em&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  📋 Summary
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;git init&lt;/code&gt;: To initialise a local directory with git.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;git status&lt;/code&gt;: To check the status of your repo i.e. to see if any file has been edited/ deleted/ added. It also shows all the tracked and untracked files. Stashed changes will not be reflected in &lt;code&gt;git status&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;git add &amp;lt;file name&amp;gt;&lt;/code&gt;/ &lt;code&gt;git add .&lt;/code&gt;: Adds changes in a particular file/ all changes in the staging area.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;git commit -m "commit message describing in short what changes are made"&lt;/code&gt;: To commit the changes.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;git remote add origin &amp;lt;remote repo url&amp;gt;&lt;/code&gt;: Connects local repo to a remote repo.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;git push -u origin &amp;lt;Local repo name&amp;gt;&lt;/code&gt;: Pushes all the committed changes from the local repo to the remote repo.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;git remote -v&lt;/code&gt;: Will list down all the remote repos that are linked to the local repo.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;git branch -a&lt;/code&gt;: To see all the branches in your repo &lt;strong&gt;(local + remote)&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;git checkout &amp;lt;branch name&amp;gt;&lt;/code&gt;: To checkout/ see the code in a branch.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;git checkout -b &amp;lt;branch name&amp;gt;&lt;/code&gt;: Create a new branch with the name &lt;code&gt;&amp;lt;branch name&amp;gt;&lt;/code&gt; and check out the same branch.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;GIT is a very powerful tool or shall I say a very elegant solution ever built to tackle a very complex challenge of version control. As one of my friends once said that the idea of multiple people working on the same product (and that too remotely) is in itself a very complicated job. GIT helps us to ease just that. And that is why it becomes so important to know GIT and all its useful commands.&lt;/p&gt;

&lt;h1&gt;
  
  
  What this blog is not about and what it rather actually is about? 👨‍💻
&lt;/h1&gt;

&lt;p&gt;To get this straight this blog is not to introduce you to GIT or what it is meant to do. Rather I assume that you know what is GIT and its basic and thus I'll jump right into the main point of this blog i.e &lt;strong&gt;&lt;em&gt;what are the most common and important GIT commands that will help you sail through more than 99% of your daily job&lt;/em&gt;&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Now there are mainly two possibilities that we should discuss here before moving forward. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;One possibility is that &lt;strong&gt;you might want to start a new project&lt;/strong&gt;. &lt;em&gt;This case mainly arises when a developer starts thinking of starting a side project/ or want to do a POC/ or simply follow along with some tutorial.&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;The second possibility is that &lt;strong&gt;you want to contribute to an existing codebase&lt;/strong&gt;. &lt;em&gt;This case can arise when you either want to contribute to an open-source project or you are in a team that is developing an application&lt;/em&gt; &lt;em&gt;(many folks working in a tech company can relate to this use-case)&lt;/em&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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F51m3mw6zb5icb7bxq4a0.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%2Fuploads%2Farticles%2F51m3mw6zb5icb7bxq4a0.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What to do when you want to start a new project. 🤔
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Create a folder for your project.&lt;/li&gt;
&lt;li&gt;Navigate to that folder &lt;em&gt;(initially the folder will be empty)&lt;/em&gt; and open the git bash terminal in that same location and type &lt;code&gt;git init&lt;/code&gt;. You will notice that a &lt;strong&gt;.git&lt;/strong&gt; folder got created in that directory. This way you can initialise the directory with git and it will now track any changes like file viz. edit/ delete/ add happening in that directory and all its direct children.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  How to track any change in files (new file added/ edited/ deleted), add it to stage and commit it? 🤔
&lt;/h3&gt;

&lt;p&gt;Now that you have initialized a directory with git, it will create a default &lt;strong&gt;master branch&lt;/strong&gt; (or &lt;strong&gt;main&lt;/strong&gt; branch as it's called in current versions) for you. We will learn about how to make other branches later. For the time being, let's make some changes in the master branch itself.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;To check what is the current status of your local git repo execute the command &lt;code&gt;git status&lt;/code&gt;. Initially, if there is no change to show, then the following message should be displayed.
&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%2Fuploads%2Farticles%2Fnnvxgt4v77vg5wro7150.png" alt="Alt Text"&gt;
&lt;/li&gt;
&lt;li&gt;Create a new file in the project root directory by using the command &lt;code&gt;touch new.txt&lt;/code&gt;. You can also create a file by the normal method of right-clicking in the directory and creating the desired file.&lt;/li&gt;
&lt;li&gt;Now execute &lt;code&gt;git status&lt;/code&gt; and it will show you that a new file has been added to the directory. It will be shown in red as the change is still not in the staging area of git. &lt;/li&gt;
&lt;li&gt;To add any new change in the staging area execute the command &lt;code&gt;git add &amp;lt;file name&amp;gt;&lt;/code&gt;. You can also do &lt;code&gt;git add .&lt;/code&gt; to add all the changes in the staging area. Once added, if you run &lt;code&gt;git status&lt;/code&gt;, it will show the change in a green colour denoting that the change is now in the staging area.&lt;/li&gt;
&lt;li&gt;To commit any change to the branch you have to execute the command &lt;code&gt;git commit -m "your commit message describing in short what changes are made"&lt;/code&gt;. Doing a &lt;code&gt;git status&lt;/code&gt; at this point (after committing) will show that there is no more change to commit (provided that you have added all the changes to staging are and then committed them) and the working tree (master branch in this case) is clean.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Please note 👆 that staging is a way of us saying to git to &lt;strong&gt;keep a track&lt;/strong&gt; of a particular file. So in case, a completely new file is added we &lt;strong&gt;HAVE&lt;/strong&gt; to add it to the staging area at least once using &lt;code&gt;git add &amp;lt;filename&amp;gt;&lt;/code&gt; or by &lt;code&gt;git add .&lt;/code&gt;. Before we add the file in the staging area &lt;code&gt;git status&lt;/code&gt; will show the file in the &lt;strong&gt;"Untracked file"&lt;/strong&gt; section as shown in the image below. &lt;/p&gt;

&lt;p&gt;But once the file has been added to the staging area at least once, any further change in the file will make it show in the &lt;strong&gt;"Changes not staged for commit"&lt;/strong&gt; section, but the file is being tracked. So to commit any subsequent change of the file in the working tree, we can directly run the command &lt;code&gt;git commit -am "Commit message"&lt;/code&gt;. For eg. if I edit the previous file (new.txt) and also create a new file say "newfile.txt" in the root then &lt;code&gt;git status&lt;/code&gt; will show the following. &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%2Fuploads%2Farticles%2Faq7yjpli56zqfadjc80w.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%2Fuploads%2Farticles%2Faq7yjpli56zqfadjc80w.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As you can see that "new.txt" is in the "Changes not staged for commit" section as I had already &lt;code&gt;git add&lt;/code&gt; this file previously and have just edited it now, whereas, on the other hand, I added a completely new file which is now showing in the &lt;strong&gt;"Untracked file"&lt;/strong&gt; section. Running &lt;code&gt;git commit -am "Commit message"&lt;/code&gt; command will only commit the changes in the tracked file "new.txt" and will NOT commit the "newfile.txt" as that is not tracked. We need to add it using &lt;code&gt;git add newfile.txt&lt;/code&gt; first and then commit it.&lt;/p&gt;

&lt;h2&gt;
  
  
  How do I connect a remote repository (repo) to my local git repo? 🤔
&lt;/h2&gt;

&lt;p&gt;In collaborative teamwork, chances are that more than one person is working on a project. In that case, you have to connect your local repo to a remote repo so that everyone can access it. Currently, our repo is in our local and no one can access it. Let connect it to a remote Github repo.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Create a new Github repo and copy the repo URL as shown in the image below. &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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fafw37bhhfpbinruefrxf.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%2Fuploads%2Farticles%2Fafw37bhhfpbinruefrxf.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;In the git bash terminal run the command &lt;code&gt;git remote add origin &amp;lt;url&amp;gt;&lt;/code&gt;. This will now connect our local repo to the remote repo. Here &lt;code&gt;origin&lt;/code&gt; is the shortcut name that we assign to the remote Github URL. Thus &lt;code&gt;origin&lt;/code&gt; = &lt;code&gt;&amp;lt;remote Github url&amp;gt;&lt;/code&gt;. It is not compulsory though but advised to name the base repo as &lt;code&gt;origin&lt;/code&gt;. &lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  How to push all the changes from local to remote. 🤔
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Run the command &lt;code&gt;git push -u origin &amp;lt;Local repo name&amp;gt;&lt;/code&gt; i.e in this case &lt;code&gt;git push -u origin master&lt;/code&gt;. This will push all the committed changes from the local repo to the remote repo. The changes will now get reflected in the remote Github repo as shown below.&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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fg8e6pdgnmowucb3nt2sz.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%2Fuploads%2Farticles%2Fg8e6pdgnmowucb3nt2sz.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Thus &lt;code&gt;git push -u origin repo-example-name-1&lt;/code&gt; will create a new branch in the remote repo with a name &lt;strong&gt;repo-example-name-1&lt;/strong&gt; &lt;em&gt;(if it is not present already)&lt;/em&gt; and &lt;strong&gt;push all the committed changes&lt;/strong&gt; from the &lt;strong&gt;local&lt;/strong&gt; branch you ran the command to the &lt;strong&gt;remote branch&lt;/strong&gt;. &lt;/li&gt;
&lt;li&gt;Please note 👆 that in a subsequent execution of &lt;code&gt;git push -u origin repo-example-name-1&lt;/code&gt; a new branch in the remote repo (with name repo-example-name-1) is not created as it is already present in the remote repo.&lt;/li&gt;
&lt;li&gt;It also sets the &lt;strong&gt;local branch to track the remote branch at the origin&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Another handy command to keep in your toolbox is the following&lt;/p&gt;

&lt;h3&gt;
  
  
  What are all the remote repo you have linked to your local repo? 🤔
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Run the command &lt;code&gt;git remote -v&lt;/code&gt; and it will list down all the remote repos that are linked to the local repo as shown in the image below. &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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fo0yah1oy6z0hn4wm2d0t.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%2Fuploads%2Farticles%2Fo0yah1oy6z0hn4wm2d0t.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It denotes that for all the &lt;strong&gt;push&lt;/strong&gt; and &lt;strong&gt;fetch&lt;/strong&gt;commands with &lt;strong&gt;origin&lt;/strong&gt; git will use the URL &lt;strong&gt;"&lt;a href="https://github.com/sohamderoy/demo-repo.git" rel="noopener noreferrer"&gt;https://github.com/sohamderoy/demo-repo.git&lt;/a&gt;"&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  How to create a new branch? And why should I create a new branch? 🤔
&lt;/h2&gt;

&lt;p&gt;Branches in git is an elegant way for a user to switch between different kinds of tasks. Let's say I have to add two new features in my application viz. a login/ signup screen and a dark mode feature. For both the features let's say I need to work with different sets of files and might have to add totally different sets of logic. In that case, it is advised to create two new branches out of the main branch and work on both the feature separately. If there is a third new feature to add, create another branch for that. Later once the feature is developed, merge that sub-branch into the main branch &lt;em&gt;(or the branch where your team prefers to keep the latest code like a &lt;strong&gt;develop&lt;/strong&gt; or &lt;strong&gt;release&lt;/strong&gt; branch for many companies)&lt;/em&gt; &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;git branch -a&lt;/code&gt;: Run this command to see all the branches in your repo &lt;strong&gt;(local + remote)&lt;/strong&gt; . The branches shown in the form &lt;code&gt;&amp;lt;branch name&amp;gt;&lt;/code&gt; is/ are the &lt;strong&gt;local branch(es)&lt;/strong&gt; in the local repo. Similarly, the branches shown in the form &lt;code&gt;remotes/origin/&amp;lt;branch name&amp;gt;&lt;/code&gt; is/ are the &lt;strong&gt;remote branch(s)&lt;/strong&gt; from the remote repo &lt;strong&gt;origin&lt;/strong&gt; connected to the local repo. &lt;/li&gt;
&lt;li&gt;
&lt;code&gt;git checkout &amp;lt;branch name&amp;gt;&lt;/code&gt;: Use this command to checkout/ see the code in a branch.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;git checkout -b &amp;lt;branch name&amp;gt;&lt;/code&gt;: Create a new branch with the name &lt;code&gt;&amp;lt;branch name&amp;gt;&lt;/code&gt; and check out the same branch.&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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fiw58jub225juvndwkoh8.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%2Fuploads%2Farticles%2Fiw58jub225juvndwkoh8.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As seen in the image above, initially there were only two branches &lt;strong&gt;master&lt;/strong&gt; &lt;em&gt;(local branch)&lt;/em&gt; and &lt;strong&gt;remotes/origin/master&lt;/strong&gt; &lt;em&gt;(remote branch)&lt;/em&gt;. After running the command &lt;code&gt;git checkout -b new-branch&lt;/code&gt; a new local branch with the name &lt;strong&gt;new-branch&lt;/strong&gt; is created. To get this branch on the remote branch run command &lt;code&gt;git push -u origin new-branch&lt;/code&gt;. &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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1l7pioez75blur91c3qd.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%2Fuploads%2Farticles%2F1l7pioez75blur91c3qd.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;👆 &lt;strong&gt;NOTE&lt;/strong&gt;: &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;It is advised to keep the name of the local and remote branches the same so that both can be recognised and linked easily.&lt;/li&gt;
&lt;li&gt;Keep the name of your branch short and descriptive so that anyone can get an idea of what that branch was created for without even looking at the code just by looking at the name.&lt;/li&gt;
&lt;li&gt;Always create a separate branch for different feature implementation.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;em&gt;puff!!! that's a lot of branches. don't worry read the section again and I am sure you'll catch the drift.&lt;/em&gt; 🙂&lt;/p&gt;

&lt;h1&gt;
  
  
  To be continued...
&lt;/h1&gt;

&lt;p&gt;I'll end Part 1 of this blog here. I hope that the content provided in this part will be helpful to all the readers. In the next part, I'll cover the rest of the git commands which are worth keeping in your toolbelt so stay tuned in. &lt;/p&gt;

&lt;p&gt;&lt;em&gt;Thanks for reading! If you like this blog and feel it's useful, do consider hitting the link button and share it with your friends, I'd really appreciate that. Stay tuned!&lt;/em&gt; 🖖&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
