我怎么做:
从另一个分支创建一个本地分支(通过 git 分支或 git checkout -b) 将本地分支推到远程存储库(即发布),但使其可追踪,以便 git pull 和 git push 工作。
我怎么做:
从另一个分支创建一个本地分支(通过 git 分支或 git checkout -b) 将本地分支推到远程存储库(即发布),但使其可追踪,以便 git pull 和 git push 工作。
当前回答
完整的 Git 工作流,以推动本地变更到另一个功能分支类似于此
排除所有远程分支
git pull --all
列出所有分支现在
git branch -a
查询或创建分支(用分支名替换 <函数分支>):
git checkout -b <feature branch>
顯示目前的分支. 必須顯示與 * 前面
git branch
添加您的本地变更(. 是目的在这里)
git add .
现在做你的改变:
git commit -m "Refactored/ Added Feature XYZ"
重要:从大师更新:
git pull origin feature-branch
点击您的本地变更:
git push origin feature-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 通常是起源(您可以修改脚本以默认起源等)。
在 Git 1.7.0 或更高版本中,您可以查看一个新的分支:
git checkout -b <branch>
编辑文件,添加和承诺. 然后按下 -u (缩写为 --set-upstream) 选项:
git push -u origin <branch>
Git 在推时将设置跟踪信息。
对于 1.7 之前的 GitLab 版本,使用:
git checkout -b name_branch
(名称_branch,前:大师)
要将其推到远程存储库,请:
git push -u origin name_new_branch
(名称_new_branch,例子:属性)
完整的 Git 工作流,以推动本地变更到另一个功能分支类似于此
排除所有远程分支
git pull --all
列出所有分支现在
git branch -a
查询或创建分支(用分支名替换 <函数分支>):
git checkout -b <feature branch>
顯示目前的分支. 必須顯示與 * 前面
git branch
添加您的本地变更(. 是目的在这里)
git add .
现在做你的改变:
git commit -m "Refactored/ Added Feature XYZ"
重要:从大师更新:
git pull origin feature-branch
点击您的本地变更:
git push origin feature-branch