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
- Open your GitHub repository and navigate to the branch dropdown menu.
- Click on the "New branch" button.
- Enter a name for your new branch (e.g., "feature/new-login-system").
- Click on the "Create branch" button.
Step 2: Checkout the new branch
- Open your terminal or command prompt and navigate to your local repository.
- 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
-
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.
-
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
- 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
- Open your GitHub repository and navigate to the branch dropdown menu.
- You should see your new branch listed.
- Verify that your changes are visible on the branch.
That's it! You have successfully pushed code to a new branch in GitHub.