How to push code to a new branch in github

To push code to a new branch in GitHub, you can follow these steps:

Step 1: Create a new branch

  1. Open your GitHub repository and navigate to the branch dropdown menu.
  2. Click on the "New branch" button.
  3. Enter a name for your new branch (e.g., "feature/new-login-system").
  4. Click on the "Create branch" button.

Step 2: Checkout the new branch

  1. Open your terminal or command prompt and navigate to your local repository.
  2. Use the following command to checkout the new branch:
    git checkout -b <branch-name>

    Replace <branch-name> with the name of the branch you created in Step 1 (e.g., "feature/new-login-system").

Step 3: Add and commit changes

  1. Make changes to your code and add them to the staging area using the following command:

    git add.

    This will stage all changes in your repository.

  2. Commit your changes using the following command:

    git commit -m "Initial commit for new login system"

    Replace the commit message with a meaningful description of your changes.

Step 4: Push changes to GitHub

  1. Use the following command to push your changes to GitHub:
    git push -u origin <branch-name>

    Replace <branch-name> with the name of the branch you created in Step 1 (e.g., "feature/new-login-system").

The -u flag sets the upstream tracking information for the branch, which allows you to push and pull changes to the branch more easily.

Step 5: Verify the branch on GitHub

  1. Open your GitHub repository and navigate to the branch dropdown menu.
  2. You should see your new branch listed.
  3. Verify that your changes are visible on the branch.

That's it! You have successfully pushed code to a new branch in GitHub.