How do you create a remote Git branch?

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

    Here is how you do it in eclipse through Egit.

    1. Go the "Git Repository Exploring" view and expand the git project to which you want to create a branch. Under Branches -> Local .. select the branch for which you want to create the branch ( In my case I selected master .. you can select another branch if you wish) .. then right click and click on Create Branch option .. and select the checkout this project option and then click the finish button.

    2. Now from the project explorer select the project .. right click then Team -> Push Branch.

    A new remote branch will be created. You can give the name of the branch to your colleagues so that they can pull it.

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

    I use this and it is pretty handy:

    git config --global alias.mkdir '!git checkout -b $1; git status; git push -u origin $1; exit;'
    

    Usage: git mkdir NEW_BRANCH

    You don't even need git status; maybe, I just want to make sure everything is going well...

    You can have BOTH the LOCAL and REMOTE branch with a single command.

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

    I know this question is well answered, but just wanted to list the steps I take to create a new branch "myNewBranch" and push to remote ("origin" in my case) and set up tracking. Consider this the "TL;DR" version :)

    # create new branch and checkout that branch
    git checkout -b myNewBranch
    # now push branch to remote 
    git push origin myNewBranch
    # set up the new branch to track remote branch from origin
    git branch --set-upstream-to=origin/myNewBranch myNewBranch
    
    0 讨论(0)
  • 2020-11-22 14:16

    Just wanted to add that while:

    git checkout -b {branchName}
    

    Creates a new branch, it also checks out that branch / makes it your current branch. If, for some reason, all you want to do is snap off a branch but not make it your current branch, then you would use the following command:

    git branch {branchName}
    

    In the first command, "checkout" makes said branch your current branch, and the "-b" means: this branch doesn't exist yet, so make it for me.

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

    git push -u <remote-name> <branch-name> doesn't work if the newly created branch isn't spawned from the same repo, i.e. if you haven't created the new branch using git checkout -b new_branch, then this will not work.

    For eg, I had cloned two different repositories locally and I had to copy repo2/branch1 to repo1/ and then push it too.

    This link helped me push my local branch (cloned from another repo) to my remote repo:

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

    Create the branch on your local machine and switch in this branch :

    $ git checkout -b [name_of_your_new_branch]
    

    Push the branch on github :

    $ git push origin [name_of_your_new_branch]
    

    When you want to commit something in your branch, be sure to be in your branch.

    You can see all branches created by using :

    $ git branch
    

    Which will show :

    * approval_messages
      master
      master_clean
    

    Add a new remote for your branch :

    $ git remote add [name_of_your_remote] 
    

    Push changes from your commit into your branch :

    $ git push origin [name_of_your_remote]
    

    Update your branch when the original branch from official repository has been updated :

    $ git fetch [name_of_your_remote]
    

    Then you need to apply to merge changes, if your branch is derivated from develop you need to do :

    $ git merge [name_of_your_remote]/develop
    

    Delete a branch on your local filesystem :

    $ git branch -d [name_of_your_new_branch]
    

    To force the deletion of local branch on your filesystem :

    $ git branch -D [name_of_your_new_branch]
    

    Delete the branch on github :

    $ git push origin :[name_of_your_new_branch]
    

    Here All Information

    Other Existing project

    0 讨论(0)
提交回复
热议问题