How do you create a remote Git branch?

后端 未结 23 2143
感情败类
感情败类 2020-11-22 13:31

I created a local branch which I want to \'push\' upstream. There is a similar question here on Stack Overflow on how to track a newly created remote branch.

Howeve

23条回答
  •  自闭症患者
    2020-11-22 14:21

    Creating a local branch from an existing branch (can be master/ develop/ any-other-branch).

    git checkout -b branch_name

    Push this to remote

    git push -u remote_name local_branch_name:remote_branch_name

    Here,

    1. -u : sets the upstream branch
    2. remote_name : git sets the name by default to be "origin" when it creates the repository. This can however be changed to a different arbitrary name.
    3. local_branch_name : is the name of the local branch to be pushed.
    4. remote_branch_name : is the name of the remote branch that we want to be created on remote.

    If we remove the local and remote branch names, it will have the format

    git push -u remote_name branch_name

    This will push the local branch to remote and with the same name as the local branch branch_name. The local branch will be tracking the remote branch as well.

提交回复
热议问题