我怎么做:
从另一个分支创建一个本地分支(通过 git 分支或 git checkout -b) 将本地分支推到远程存储库(即发布),但使其可追踪,以便 git pull 和 git push 工作。
我怎么做:
从另一个分支创建一个本地分支(通过 git 分支或 git checkout -b) 将本地分支推到远程存储库(即发布),但使其可追踪,以便 git pull 和 git push 工作。
当前回答
我只是做
git push -u origin localBranch:remoteBranchToBeCreated
这是一个已经克隆的项目。
Git 创建了一个新的分支,名为远程BranchToBeCreated 在我在本地Branch 所做的承诺下。
Edit: This changes your current local branch ( possibly named localBranch) upstream to origin/remoteBranchToBeCreated. 要修复这一点,只需输入:
git branch --set-upstream-to=origin/localBranch
或
git branch -u origin/localBranch
因此,您目前的本地分支机构现在跟踪起源/本地分支。
其他回答
在 Git 1.7.0 或更高版本中,您可以查看一个新的分支:
git checkout -b <branch>
编辑文件,添加和承诺. 然后按下 -u (缩写为 --set-upstream) 选项:
git push -u origin <branch>
Git 在推时将设置跟踪信息。
这里已经提供的解决方案的轻微变化:
创建一个本地分支,基于某些其他(远程或本地)分支: git checkout -b 分支名称 将本地分支推到远程存储库(发布),但使其可追踪,所以 git pull 和 git push 将立即运行 git push -u 起源 HEAD 使用 HEAD 是一个“手动的方式,将当前分支推到相同的名称在远程”。 来源: https://git-scm.com/docs/git-push 在 Git 条款中, HEAD (in)
编辑 过时,只需使用 git push -u 起源 $BRANCHNAME
使用William的错误的Git工具的Git出版分支。
好吧,没有卢比,所以 - 忽略保留! - 采取脚本的最后三行,并创建一个 bash 脚本, 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}
然后运行 git-publish-branch REMOTENAME BRANCHNAME,在那里 REMOTENAME 通常是起源(您可以修改脚本以默认起源等)。
你可以在2个步骤中完成:
使用支票来创建本地分支:
git checkout -b yourBranchName
随心所欲地与你的分支工作。
使用推命令自我创建分支,并将代码发送到远程存储库:
git push -u origin yourBanchName
有很多方法可以做到这一点,但我认为这很简单。
简单地说,要创建一个新的地方分支,做:
git branch <branch-name>
要将其推到远程存储库,请:
git push -u origin <branch-name>