How do I push a new local branch to a remote Git repository and track it too?

后端 未结 15 1301
逝去的感伤
逝去的感伤 2020-11-22 09:17

I want to be able to do the following:

  1. Create a local branch based on some other (remote or local) branch (via git branch or git checkout

15条回答
  •  隐瞒了意图╮
    2020-11-22 10:15

    I suppose that you have already cloned a project like:

    git clone http://github.com/myproject.git
    
    1. Then in your local copy, create a new branch and check it out:

      git checkout -b 
      
    2. Supposing that you made a "git bare --init" on your server and created the myapp.git, you should:

      git remote add origin ssh://example.com/var/git/myapp.git
      git push origin master
      
    3. After that, users should be able to

      git clone http://example.com/var/git/myapp.git
      

    NOTE: I'm assuming that you have your server up and running. If it isn't, it won't work. A good how-to is here.

    ADDED

    Add a remote branch:

    git push origin master:new_feature_name
    

    Check if everything is good (fetch origin and list remote branches):

    git fetch origin
    git branch -r
    

    Create a local branch and track the remote branch:

    git checkout -tb new_feature_name origin/new_feature_name
    

    Update everything:

    git pull
    

提交回复
热议问题