Git create new remote branch
To create a new remote branch in Git, you can use the following command:
git push origin <new-branch-name>:<new-branch-name>
Replace <new-branch-name>
with the name you want to give to your new branch.
For example, to create a new branch called feature/new-login-system
, you would run:
git push origin feature/new-login-system:feature/new-login-system
This will create a new branch on the remote repository (in this case, origin
) with the name feature/new-login-system
.
If you want to create a new branch that tracks an existing branch (e.g., master
), you can use the following command:
git push origin HEAD:refs/heads/<new-branch-name>
This will create a new branch on the remote repository that tracks the current branch (i.e., the branch you are currently on).
For example, to create a new branch called feature/new-login-system
that tracks the master
branch, you would run:
git push origin HEAD:refs/heads/feature/new-login-system
Note that if you want to create a new branch that is not tracked by any existing branch, you will need to specify the commit hash or tag that you want the new branch to start from. For example:
git push origin <commit-hash>:refs/heads/<new-branch-name>
Replace <commit-hash>
with the commit hash of the commit you want the new branch to start from, and <new-branch-name>
with the name you want to give to your new branch.