Git push to a new branch

To push changes to a new branch in Git, you can follow these steps:

  1. Create a new branch:

    git branch <branch-name>

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

  2. Switch to the new branch:

    git checkout <branch-name>

    This will switch your local repository to the new branch.

  3. Make changes to your code and commit them:

    git add <files>
    git commit -m "Initial commit for new branch"

    Replace <files> with the files you want to commit, and replace "Initial commit for new branch" with a meaningful commit message.

  4. Push the new branch to the remote repository:

    git push -u origin <branch-name>

    Replace <branch-name> with the name of the branch you created in step 1. The -u flag sets the upstream tracking information for the branch, which allows you to use git pull and git push without specifying the branch name.

For example, if you created a new branch called feature/new-login-system, you would run:

git push -u origin feature/new-login-system

This will create a new branch on the remote repository and set the upstream tracking information.

Note: If you want to push changes to a new branch without creating a new branch on the remote repository, you can use the -n flag:

git push -n origin <branch-name>

This will create a new branch on the remote repository, but it will not set the upstream tracking information.