How do you create a remote Git branch?

后端 未结 23 1889
感情败类
感情败类 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:07

    Easiest Solution... Drumm Roll... git version 2.10.1 (Apple Git-78)

    1) git checkout -b localBranchNameThatDoesNotExistInRemote
    
    2) Do your changes, and do a git commit 
    
    3) git push origin localBranchNameThatDoesNotExistInRemote --force
    

    N.B. - The branch you just created in your local environment, and the remote non-existing branch where you are trying to push, must have the same name.

    0 讨论(0)
  • 2020-11-22 14:09

    As stated in the previous answers,

    git push <remote-name> <local-branch-name>:<remote-branch-name>
    

    is enough for pushing a local branch.

    Your colleagues, can pull all remote branches (including new ones) with this command:

    git remote update
    

    Then, to make changes on the branch, the usual flow:

    git checkout -b <local-branch-name> <remote-name>/<remote-branch-name>
    
    0 讨论(0)
  • 2020-11-22 14:09

    Create a new branch locally based on the current branch:

    git checkout -b newbranch
    

    Commit any changes as you normally would. Then, push it upstream:

    git push -u origin HEAD
    

    This is a shortcut to push the current branch to a branch of the same name on origin and track it so that you don't need to specify origin HEAD in the future.

    0 讨论(0)
  • 2020-11-22 14:10

    If you want to create a branch from the current branch

    git checkout -b {your_local_branch_name} 
    

    you want a branch from a remote branch, you can try

    git checkout -b {your_local_branch_name} origin/<remote_branch_name>
    

    If you are done with changes you can add the file.

    git add -A or git add <each_file_names>
    

    Then do a commit locally

    git commit -m 'your commit message'
    

    When you want to push to remote repo

    git push -u origin <your_local_branch_name>
    

    All together will be

    git checkout -b bug_fixes 
    

    or If you want to create a branch from a remote branch say development

    git checkout -b bug_fixes origin/development

    You can push to the branch to remote repo by

    git push -u origin bug_fixes
    

    Anytime you want to update your branch from any other branch say master.

    git pull origin master.

    0 讨论(0)
  • 2020-11-22 14:11

    If you wanna actually just create remote branch without having the local one, you can do it like this:

    git push origin HEAD:refs/heads/foo
    

    It pushes whatever is your HEAD to branch foo that did not exist on the remote.

    0 讨论(0)
  • 2020-11-22 14:11

    How to do through Source Tree

     1: Open SourceTree, click on Repository -> Checkout
     2: Click on Create New Branch
     3: Select the branch where you want to get code for new branch 
     4: Give your branch name
     5: Push the branch  (by click on Push-button)
    
    0 讨论(0)
提交回复
热议问题