<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: caleb-ali</title>
    <description>The latest articles on Forem by caleb-ali (@calebali).</description>
    <link>https://forem.com/calebali</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%2F409691%2F5e14fe2a-3c38-4802-b636-13d62a1cb527.jpg</url>
      <title>Forem: caleb-ali</title>
      <link>https://forem.com/calebali</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/calebali"/>
    <language>en</language>
    <item>
      <title>How to Build Dynamic Charts in React with Recharts (Including Edge Cases)</title>
      <dc:creator>caleb-ali</dc:creator>
      <pubDate>Wed, 21 May 2025 17:16:01 +0000</pubDate>
      <link>https://forem.com/calebali/how-to-build-dynamic-charts-in-react-with-recharts-including-edge-cases-3e72</link>
      <guid>https://forem.com/calebali/how-to-build-dynamic-charts-in-react-with-recharts-including-edge-cases-3e72</guid>
      <description>&lt;p&gt;&lt;strong&gt;Introduction&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Visualizing data is crucial for understanding trends and distributions in web applications. Recharts, a popular React charting library, makes it easy to create interactive and responsive charts by combining the power of D3 with the flexibility of React components. It offers a sweet spot between customization and ease of use, whether you're building analytics dashboards or simple data displays while keeping bundle size in check.&lt;/p&gt;

&lt;p&gt;In this article, we'll explore:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Building a Line Chart (for time-based trends)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Building a Pie Chart (for percentage distributions)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Handling Edge Cases in a Pie Chart (e.g when one category is 100%)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Dynamic Data Fetching &amp;amp; Optimization (using useMemo for performance)&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Setting Up Recharts&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;First, install Recharts in your React project:&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Building a Line Chart (for time-based trends)&lt;/strong&gt;&lt;br&gt;
A line chart is ideal for showing trends over time (e.g., ticket sales by month).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Key Features:&lt;/strong&gt;&lt;br&gt;
Displays time-based data&lt;/p&gt;

&lt;p&gt;Supports tooltips, legends, and custom styling&lt;/p&gt;

&lt;p&gt;Responsive design&lt;/p&gt;

&lt;p&gt;Implementation:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import "./styles.css";
import {
  LineChart, 
  Line,
  XAxis,
  YAxis,
  CartesianGrid,
  Tooltip,
  Legend,
  ResponsiveContainer,
} from "recharts";

const data = [
  {
    name: "jan",
    free: 1000,


  },
  {
    name: "feb",
    free: 1400,


  },
  {
    name: "mar",
    free: 800,


  },
  {
    name: "apr",
    free: 1000,


  },
  {
    name: "may",
    free: 800,



  },
  {
    name: "jun",
    free: 1000,


  },
  {
    name: "jul",
    free: 2000,


  },
  {
    name: "aug",
    free: 1300,



  },
  {
    name: "sep",
    free: 1000,



  },
  {
    name: "oct",
    free: 1000,



  },
  {
    name: "nov",
    free: 1000,



  },
  {
    name: "dec",
    free: 1000,


  }

];

export default function App() {
  return (
    &amp;lt;LineChart
      width={500}
      height={300}
      data={data} // Data array (each object represents a point on the chart)
      margin={{
        top: 5,
        right: 30,
        left: 20,
        bottom: 5,
      }}
    &amp;gt;
      &amp;lt;CartesianGrid strokeDasharray="3 3" /&amp;gt; // Grid lines (dashed style)
        &amp;lt;XAxis 
    dataKey="name"  
    padding={{ left: 20, right: 20 }}  
  /&amp;gt;
      &amp;lt;YAxis /&amp;gt;
      &amp;lt;Tooltip /&amp;gt;

      &amp;lt;Line
        type="monotone"
        dataKey="free"
        stroke="#8884d8"
        activeDot={{ r: 8 }}
      /&amp;gt;

    &amp;lt;/LineChart&amp;gt;
  );
}

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

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.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%2F4suxni4gu96wcgeu5qw6.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2F4suxni4gu96wcgeu5qw6.jpeg" alt="single dataset" width="800" height="474"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Comparing multiple datasets in a Line chart&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { LineChart, Line, XAxis, YAxis, CartesianGrid, Tooltip, Legend, ResponsiveContainer } from 'recharts';

const data = [
  {
    name: "jan",
    free: 1000,
    paid: 500,
  },
  {
    name: "feb",
    free: 1400,
    paid: 800,
  },
  {
    name: "mar",
    free: 800,
    paid: 400,
  },
  {
    name: "apr",
    free: 1000,
    paid: 900,
  },
  {
    name: "may",
    free: 800,
    paid: 1200,
  },
  {
    name: "jun",
    free: 1000,
    paid: 400,
  },
  {
    name: "jul",
    free: 2000,
    paid: 1200,
  },
  {
    name: "aug",
    free: 1300,
    paid: 900,
  },
  {
    name: "sep",
    free: 1000,
    paid: 300,
  },
  {
    name: "oct",
    free: 1000,
    paid: 600,
  },
  {
    name: "nov",
    free: 1000,
    paid: 800,
  },
  {
    name: "dec",
    free: 1000,
    paid: 400,
  },
];

export default function App() {
  return (
    &amp;lt;LineChart
      width={500}
      height={300}
      data={data}
      margin={{
        top: 5,
        right: 30,
        left: 20,
        bottom: 5,
      }}
    &amp;gt;
      &amp;lt;CartesianGrid strokeDasharray="3 3" /&amp;gt;
      &amp;lt;XAxis dataKey="name" padding={{ left: 20, right: 20 }} /&amp;gt;
      &amp;lt;YAxis /&amp;gt;
      &amp;lt;Tooltip /&amp;gt;
      &amp;lt;Legend /&amp;gt;
      &amp;lt;Line
        type="monotone"
        dataKey="free"
        stroke="#8884d8"
        activeDot={{ r: 8 }}
      /&amp;gt;
      &amp;lt;Line type="monotone" dataKey="paid" stroke="#82ca9d" /&amp;gt;
    &amp;lt;/LineChart&amp;gt;
  );
}

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

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.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%2F3s9oone0p8ltghtdz9r0.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2F3s9oone0p8ltghtdz9r0.jpeg" alt="multiple dataset" width="800" height="495"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Building a Pie Chart&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;We'll look at both the basic implementation and the improved version with edge case handling.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Basic Implementation&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { PieChart, Pie, Cell } from "recharts";

const data = [
  { name: "Free", value: 400 },
  { name: "Paid", value: 300 },
];

const COLORS = ["#0088FE", "#00C49F"];

const RADIAN = Math.PI / 180;
const renderCustomizedLabel = ({
  cx,
  cy,
  midAngle,
  innerRadius,
  outerRadius,
  percent,
  index,
}) =&amp;gt; {
  const radius = innerRadius + (outerRadius - innerRadius) * 0.5;
  const x = cx + radius * Math.cos(-midAngle * RADIAN);
  const y = cy + radius * Math.sin(-midAngle * RADIAN);

  return (
    &amp;lt;text
      x={x}
      y={y}
      fill="white"
      textAnchor={x &amp;gt; cx ? "start" : "end"}
      dominantBaseline="central"
    &amp;gt;
      {`${(percent * 100).toFixed(0)}%`}
    &amp;lt;/text&amp;gt;
  );
};
export default function App() {
  return (
    &amp;lt;PieChart width={400} height={400}&amp;gt;
      &amp;lt;Pie
        data={data}
        cx={200}
        cy={200}
        labelLine={false}
        label={renderCustomizedLabel}
        outerRadius={80}
        fill="#8884d8"
        dataKey="value"
      &amp;gt;
        {data.map((entry, index) =&amp;gt; (
          &amp;lt;Cell key={`cell-${index}`} fill={COLORS[index % COLORS.length]} /&amp;gt;
        ))}
      &amp;lt;/Pie&amp;gt;
    &amp;lt;/PieChart&amp;gt;
  );
}

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

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.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%2F8mseah7qelkr7yxtt50p.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2F8mseah7qelkr7yxtt50p.jpeg" alt="basic piechart" width="746" height="491"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Limitations of this approach:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;When one value is 100% and the other is 0%, the chart shows a tiny white line&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The labels can become cramped or overlap in edge cases&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;There's no special handling for 100% dominance cases&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.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%2F3utpioz7hks5h9m63rub.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2F3utpioz7hks5h9m63rub.jpeg" alt="edge case" width="800" height="595"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here's the improved version that properly handles all cases:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { PieChart, Pie, Cell, ResponsiveContainer } from "recharts";

const data = [
  { name: "Free", value: 100 },
  { name: "Paid", value: 0 },
];

const COLORS = ["#0088FE", "#00C49F"];

const RADIAN = Math.PI / 180;

const renderCustomizedLabel = ({
  cx,
  cy,
  midAngle,
  innerRadius,
  outerRadius,
  percent,
  index,
}) =&amp;gt; {
  const has100Percent = data.some((item) =&amp;gt; item.value === 100);

  if (has100Percent) {
    const dominantItem = data.find((item) =&amp;gt; item.value === 100);
    return (
      &amp;lt;text
        x={cx}
        y={cy}
        fill="white"
        textAnchor="middle"
        dominantBaseline="central"
        style={{ fontSize: "16px", fontWeight: "bold" }}
      &amp;gt;
        {`${dominantItem.name}: 100%`}
      &amp;lt;/text&amp;gt;
    );
  }

  return null;
};

const PieChartComponent = () =&amp;gt; {
  // Filter out 0% values
  const filteredData = data.filter((item) =&amp;gt; item.value &amp;gt; 0);

  return (
    &amp;lt;ResponsiveContainer width="100%" height={400}&amp;gt;
      &amp;lt;PieChart&amp;gt;
        &amp;lt;Pie
          data={filteredData} // Use filtered data here
          cx="50%"
          cy="50%"
          labelLine={false}
          label={renderCustomizedLabel}
          outerRadius={80}
          fill="#8884d8"
          dataKey="value"
          stroke="none"
        &amp;gt;
          {filteredData.map((entry, index) =&amp;gt; (
            &amp;lt;Cell key={`cell-${index}`} fill={COLORS[index % COLORS.length]} /&amp;gt;
          ))}
        &amp;lt;/Pie&amp;gt;
      &amp;lt;/PieChart&amp;gt;
    &amp;lt;/ResponsiveContainer&amp;gt;
  );
};

export default PieChartComponent;

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

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.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%2Fhmfq3cr8vn72z5ba6k6y.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fhmfq3cr8vn72z5ba6k6y.jpeg" alt="fixed edgecase" width="800" height="503"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Finally we'll explore how to fetch and display dynamic data in your charts, focusing on performance optimization with useMemo&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why Use useMemo for Dynamic Charts?&lt;/strong&gt;&lt;br&gt;
When working with dynamic data in React charts, useMemo provides two key benefits:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Performance Optimization: It prevents unnecessary recalculations of your chart data on every render&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Stable References: It ensures your chart components don't re-render unless the actual data changes&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Dynamic Line Chart Implementation&lt;/strong&gt;&lt;br&gt;
Here's how to implement a dynamic line chart that works with fetched data&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { useState, useEffect, useMemo } from 'react';
import { LineChart, Line, XAxis, YAxis, CartesianGrid, Tooltip, Legend, ResponsiveContainer } from 'recharts';
import { useSalesData } from "lib/hooks";


const DynamicLineChart = ({ eventId }) =&amp;gt; {

//assuming useSalesData is the hook i am fetching my sales data from
  const { data: salesData, loading } = useSalesData(eventId);

  // Transform data for the chart
  const chartData = useMemo(() =&amp;gt; {
    if (!salesData?.monthlySales) return [];

    return salesData.monthlySales.map(month =&amp;gt; ({
      name: month.month,
      free: month.free,
      paid: month.paid
    }));
  }, [salesData]);

  if (loading) return &amp;lt;div&amp;gt;Loading chart data...&amp;lt;/div&amp;gt;;

  return (
    &amp;lt;ResponsiveContainer width="100%" height={300}&amp;gt;
      &amp;lt;LineChart
        data={chartData}
        margin={{ top: 5, right: 30, left: 20, bottom: 5 }}
      &amp;gt;
        &amp;lt;CartesianGrid strokeDasharray="3 3" /&amp;gt;
        &amp;lt;XAxis dataKey="name" /&amp;gt;
        &amp;lt;YAxis /&amp;gt;
        &amp;lt;Tooltip /&amp;gt;
        &amp;lt;Legend /&amp;gt;
        &amp;lt;Line 
          type="monotone" 
          dataKey="free" 
          stroke="#8884d8" 
          activeDot={{ r: 8 }} 
        /&amp;gt;
        &amp;lt;Line 
          type="monotone" 
          dataKey="paid" 
          stroke="#82ca9d" 
        /&amp;gt;
      &amp;lt;/LineChart&amp;gt;
    &amp;lt;/ResponsiveContainer&amp;gt;
  );
};

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Dynamic Pie Chart Implementation&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Here's how to implement a dynamic pie chart that works with fetched data&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { useState, useEffect, useMemo } from 'react';
import { PieChart, Pie, Cell, ResponsiveContainer } from 'recharts';
import { useTicketTypeData } from "lib/hooks";


const COLORS = ['#0088FE', '#00C49F'];

const DynamicPieChart = ({ eventId }) =&amp;gt; {
//assuming useTicketTypeData is the hook i am fetching my ticket type data from
  const { data: ticketData, loading } = useTicketTypeData(eventId);

  // Transform data for the pie chart
  const pieData = useMemo(() =&amp;gt; {
    if (!ticketData?.ticketTypes) return [];

    const total = ticketData.ticketTypes.free + ticketData.ticketTypes.paid;
    return [
      { 
        name: 'Free', 
        value: total &amp;gt; 0 ? (ticketData.ticketTypes.free / total) * 100 : 0 
      },
      { 
        name: 'Paid', 
        value: total &amp;gt; 0 ? (ticketData.ticketTypes.paid / total) * 100 : 0 
      }
    ];
  }, [ticketData]);

  if (loading) return &amp;lt;div&amp;gt;Loading pie chart data...&amp;lt;/div&amp;gt;;

  return (
    &amp;lt;ResponsiveContainer width="100%" height={300}&amp;gt;
      &amp;lt;PieChart&amp;gt;
        &amp;lt;Pie
          data={pieData}
          cx="50%"
          cy="50%"
          labelLine={false}
          label={({ name, percent }) =&amp;gt; `${name}: ${(percent * 100).toFixed(0)}%`}
          outerRadius={80}
          fill="#8884d8"
          dataKey="value"
        &amp;gt;
          {pieData.map((entry, index) =&amp;gt; (
            &amp;lt;Cell key={`cell-${index}`} fill={COLORS[index % COLORS.length]} /&amp;gt;
          ))}
        &amp;lt;/Pie&amp;gt;
      &amp;lt;/PieChart&amp;gt;
    &amp;lt;/ResponsiveContainer&amp;gt;
  );
};

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;br&gt;
Recharts provides a powerful yet simple way to create dynamic, interactive data visualizations in React. By combining efficient data fetching with smart memoization techniques, you can build performant dashboards that gracefully handle real-world data scenarios. Remember to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Always memoize data transformations with useMemo&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Handle loading and error states&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Consider edge cases like 100% values in pie charts&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Leverage Recharts' responsive containers for mobile-friendly displays&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;With these patterns, you're well-equipped to create production-ready visualizations that bring your data to life.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;References &amp;amp; Further Reading&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://recharts.org/en-US" rel="noopener noreferrer"&gt;Recharts Official Documentation&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://recharts.org/en-US/api" rel="noopener noreferrer"&gt;Recharts API Reference&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://react.dev/reference/react/useMemo" rel="noopener noreferrer"&gt;React useMemo Documentation&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>react</category>
      <category>datavisualization</category>
      <category>typescript</category>
      <category>rechart</category>
    </item>
    <item>
      <title>How To Push To A Branch On Github From Vscode</title>
      <dc:creator>caleb-ali</dc:creator>
      <pubDate>Mon, 15 Jun 2020 19:37:00 +0000</pubDate>
      <link>https://forem.com/calebali/how-to-push-to-a-branch-on-github-from-vscode-2c40</link>
      <guid>https://forem.com/calebali/how-to-push-to-a-branch-on-github-from-vscode-2c40</guid>
      <description>&lt;p&gt;If you are reading this, you will probably have heard of GitHub or are even using it. GitHub is a repository hosting server for Git. Today I would like to show you how to push a code from your vscode editor to a branch of a repository you have created on GitHub.&lt;/p&gt;

&lt;p&gt;For the purpose of this article I will be assuming&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;you already have vscode and Gitbash installed on your PC &lt;/li&gt;
&lt;li&gt;you have created a repository on GitHub&lt;/li&gt;
&lt;li&gt;you want to push the code to a branch other than the master branch&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;open the project you want to push on your vscode editor, click on the Terminal button at the top Left corner of the screen, click on New Terminal. A new terminal will open at the bottom of the screen. follow the steps below to push your code to a new branch.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;git init&lt;/li&gt;
&lt;li&gt;git branch "name" ( where name is the name of the new 
branch)&lt;/li&gt;
&lt;li&gt;git branch (you should see the new branch listed )&lt;/li&gt;
&lt;li&gt;git checkout "name" (to select your new branch)&lt;/li&gt;
&lt;li&gt;git remote add "name" "url" (to get the url open your 
repository on Github, click the clone or download button 
and copy the url)&lt;/li&gt;
&lt;li&gt;git push --set-upstream "name" "name"
If you encounter an error in the last step input (git 
push "name") it would display an error and display the 
right code for you below, copy the code and paste it 
back and your code would be uploaded to your desired 
branch.&lt;/li&gt;
&lt;/ul&gt;

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