Git push to new remote branch
To push a local branch to a new remote branch, you can use the following command:
git push -u origin <local-branch-name>:<remote-branch-name>
Here:
origin
is the name of the remote repository (you can replace it with the actual name of your remote repository if it's different).<local-branch-name>
is the name of the local branch you want to push.<remote-branch-name>
is the name of the new remote branch you want to create.
For example, if you want to push a local branch called feature/new-login-system
to a new remote branch called feature/new-login-system
on the remote repository origin
, you would use the following command:
git push -u origin feature/new-login-system:feature/new-login-system
The -u
flag tells Git to set the upstream tracking information for the local branch, so that subsequent git pull
and git push
commands will know which remote branch to use.
If you want to push a local branch to a new remote branch with a different name, you can specify the remote branch name separately. For example:
git push -u origin feature/new-login-system:refs/heads/new-login-system
This would create a new remote branch called new-login-system
on the remote repository origin
, and set the upstream tracking information for the local branch feature/new-login-system
.
Note that if you want to push a local branch to an existing remote branch, you can simply use the following command:
git push origin <local-branch-name>
This will update the existing remote branch with the changes from your local branch.