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

后端 未结 15 1609
逝去的感伤
逝去的感伤 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:11

    edit Outdated, just use git push -u origin $BRANCHNAME


    Use git publish-branch from William's miscellaneous Git tools (gitorious repo and clone).

    OK, no Ruby, so - ignoring the safeguards! - take the last three lines of the script and create a bash script, git-publish-branch:

    #!/bin/bash
    REMOTE=$1 # Rewrite this to make it optional...
    BRANCH=$2
    # Uncomment the following line to create BRANCH locally first
    #git checkout -b ${BRANCH}
    git push ${ORIGIN} ${BRANCH}:refs/heads/${BRANCH} &&
    git config branch.${BRANCH}.remote ${REMOTE} &&
    git config branch.${BRANCH}.merge refs/heads/${BRANCH}
    

    Then run git-publish-branch REMOTENAME BRANCHNAME, where REMOTENAME is usually origin (you may modify the script to take origin as default, etc...)

提交回复
热议问题