How to push to new branch

To push your local branch to a new branch on a remote repository, you can use the following Git commands:

  1. Create a new branch:

    git branch <new-branch-name>

    Replace <new-branch-name> with the name you want to give to your new branch.

  2. Switch to the new branch:

    git checkout <new-branch-name>

    This will switch your local repository to the new branch.

  3. Add and commit your changes:

    git add.
    git commit -m "Initial commit on new branch"

    This will stage all changes in your local repository and commit them with a meaningful commit message.

  4. Push the new branch to the remote repository:

    git push -u origin <new-branch-name>

    Replace origin with the name of your remote repository (usually origin or upstream).

The -u flag sets the upstream tracking information for the branch, which allows you to use git pull and git push without specifying the remote branch.

For example, if you want to create a new branch called feature/new-login-system, you would run the following commands:

git branch feature/new-login-system
git checkout feature/new-login-system
git add.
git commit -m "Initial commit on new branch"
git push -u origin feature/new-login-system

This will create a new branch called feature/new-login-system on your remote repository, and set the upstream tracking information for that branch.

Note: If you want to push an existing branch to a new branch on the remote repository, you can use the following command:

git push origin <local-branch-name>:<new-branch-name>

For example:

git push origin master:feature/new-login-system

This will push the changes from your local master branch to a new branch called feature/new-login-system on the remote repository.