Skip to main content

Mastering Your React Project: Push to GitHub in Both Main and Master Branch from VS Code!

As of the last update in September 2021, GitHub had announced that they would replace the "master" branch with "main" as the default branch name. So, the steps I'll provide will use "main" as the default branch name. If anything has changed after last update, you can adapt the steps accordingly.


Here's how you can push your React project to GitHub from VS Code in both the "main" and "master" branches:



1. Initialize a Git repository:

If your React project is not already a Git repository, you can initialize it by opening a terminal in VS Code and running the following command in the root of your project:


```bash

git init

```


2. Add your files to the Git repository:

Run the following command to stage all the changes you want to commit:


```bash

git add .

```


3. Commit your changes:

Create a commit for the staged changes with a meaningful message:


```bash

git commit -m "Your commit message here"

```


4. Create the "main" branch:

By default, Git will create a "master" branch, but we want to use "main" instead. So, we'll create the "main" branch and push our initial commit to it:


```bash

git branch -M main

git push -u origin main

```


5. Create the "master" branch:

Now that we have pushed the initial commit to the "main" branch, let's create the "master" branch and push the same commit to it:


```bash

git checkout -b master

git push -u origin master

```


6. Keep both branches in sync:

After the initial setup, you can continue working on your project and make changes. Whenever you want to push changes to GitHub, follow these steps:


- Stage your changes with `git add .`

- Commit the changes with `git commit -m "Your commit message here"`


Now, to push the changes to both branches, simply run:


```bash

git push origin main

git push origin master

```


These commands will push your changes to the respective branches on your GitHub repository.


Please note that "origin" is the default name for the remote repository in Git. If you have a different remote name, replace "origin" with the appropriate remote name. Additionally, if GitHub has made any changes to their default branch naming convention after my last update, adjust the branch names accordingly.

Comments

Popular posts from this blog

The Rise of Headless CMS: Benefits and Use Cases

 Title: The Rise of Headless CMS: Benefits and Use Cases In recent years, there has been a significant rise in the adoption of headless Content Management Systems (CMS). This new approach to content management is revolutionizing the way websites and applications are built and managed. In simple terms, a headless CMS decouples the front-end presentation layer from the back-end content management system. Instead of using a traditional monolithic CMS where the front-end and back-end are tightly integrated, a headless CMS allows developers to build the front-end separately and fetch content through APIs. Let's explore the benefits and use cases of headless CMS. 1. Flexibility and Faster Development: One of the key benefits of a headless CMS is the flexibility it provides to developers. Since the front-end and back-end are independent, developers can choose the most suitable technologies for each. This means they can use the latest and most efficient tools for creating interactive user ...

"Decoding CMS: Unveiling the Power Behind Content Management Systems"

 Title: The Power of Content Management Systems (CMS) Content Management Systems (CMS) have revolutionized the way we manage and present digital content. In a rapidly evolving digital landscape, where the demand for dynamic and engaging websites is ever-increasing, CMS platforms provide a versatile solution for content creation, organization, and publication. CMS empowers individuals, businesses, and organizations to efficiently manage their websites without the need for technical expertise. From bloggers to large enterprises, the adoption of CMS has become a game-changer in the world of web development. At its core, a CMS is a software application that simplifies the process of content creation, editing, and publishing on websites. It allows users to manage various content types, including text, images, videos, and more, with ease. The beauty of CMS lies in its user-friendly interface, where users can update their website's content through a simple web browser without touching any...