Create new branch and push git
Here are the steps to create a new branch and push it to a remote repository using Git:
Step 1: Create a new branch
Open your terminal and navigate to your local Git repository. Run the following command to create a new branch:
git branch <branch-name>
Replace <branch-name>
with the name you want to give your new branch. For example:
git branch feature/new-login-system
This will create a new branch called feature/new-login-system
that is based on the current branch (usually master
).
Step 2: Switch to the new branch
To start working on the new branch, you need to switch to it. Run the following command:
git checkout <branch-name>
Replace <branch-name>
with the name of the new branch you created in Step 1. For example:
git checkout feature/new-login-system
This will switch your local repository to the new branch.
Step 3: Make changes and commit them
Make some changes to your code, add them to the staging area, and commit them. For example:
git add.
git commit -m "Initial commit for new login system"
This will create a new commit with the message "Initial commit for new login system".
Step 4: Push the new branch to the remote repository
To push the new branch to the remote repository, run the following command:
git push origin <branch-name>
Replace <branch-name>
with the name of the new branch. For example:
git push origin feature/new-login-system
This will create a new branch on the remote repository with the same name as the local branch.
Step 5: Verify the branch on the remote repository
To verify that the branch has been successfully pushed to the remote repository, run the following command:
git branch -a
This will list all branches in your local repository, including the new branch. You should see the new branch listed with the remote tracking information.
Alternatively, you can use the following command to verify the branch on the remote repository:
git ls-remote --heads origin
This will list all branches on the remote repository, including the new branch.
That's it! You have now created a new branch, made changes to it, and pushed it to the remote repository.