我怎么做:
从另一个分支创建一个本地分支(通过 git 分支或 git checkout -b) 将本地分支推到远程存储库(即发布),但使其可追踪,以便 git pull 和 git push 工作。
我怎么做:
从另一个分支创建一个本地分支(通过 git 分支或 git checkout -b) 将本地分支推到远程存储库(即发布),但使其可追踪,以便 git pull 和 git push 工作。
当前回答
创建一个新的分支,通过从现有分支中分支
git checkout -b <new_branch>
然后将这个新分支推到存储库使用
git push -u origin <new_branch>
此创建并推动所有本地承诺到新创建的远程分支起源/<new_branch>
其他回答
我认为这是最简单的 alias,添加到你的 ~/.gitconfig
[alias]
publish-branch = !git push -u origin $(git rev-parse --abbrev-ref HEAD)
你只是跑
git publish-branch
而且......它出版了分支。
在引入 git push -u之前,没有 git push 选项可以获得你想要的东西。
如果您创建一个新的分支,使用:
$ git checkout -b branchB
$ git push origin branchB:branchB
您可以使用 git config 命令,以避免直接编辑.git/config 文件:
$ git config branch.branchB.remote origin
$ git config branch.branchB.merge refs/heads/branchB
或者您可以手动编辑.git/config 文件以添加跟踪信息到该分支:
[branch "branchB"]
remote = origin
merge = refs/heads/branchB
编辑 过时,只需使用 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 通常是起源(您可以修改脚本以默认起源等)。
对于 1.7 之前的 GitLab 版本,使用:
git checkout -b name_branch
(名称_branch,前:大师)
要将其推到远程存储库,请:
git push -u origin name_new_branch
(名称_new_branch,例子:属性)
我创建了一个标签,所以每当我创建一个新的分支,它将按下推和跟踪远程分支。
# Create a new branch, push to origin and track that remote branch
publishBranch() {
git checkout -b $1
git push -u origin $1
}
alias gcb=publishBranch
使用: 只是用 thuy/do-sth-kool 输入 gcb thuy/do-sth-kool 是我的新分支名称。