我怎么做:
从另一个分支创建一个本地分支(通过 git 分支或 git checkout -b) 将本地分支推到远程存储库(即发布),但使其可追踪,以便 git pull 和 git push 工作。
我怎么做:
从另一个分支创建一个本地分支(通过 git 分支或 git checkout -b) 将本地分支推到远程存储库(即发布),但使其可追踪,以便 git pull 和 git push 工作。
当前回答
现在可以(Git 版本 2.37.0)设置 git config --global push.autoSetupRemote true。
其他回答
你可以在2个步骤中完成:
使用支票来创建本地分支:
git checkout -b yourBranchName
随心所欲地与你的分支工作。
使用推命令自我创建分支,并将代码发送到远程存储库:
git push -u origin yourBanchName
有很多方法可以做到这一点,但我认为这很简单。
简单地说,要创建一个新的地方分支,做:
git branch <branch-name>
要将其推到远程存储库,请:
git push -u origin <branch-name>
完整的 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
我认为这是最简单的 alias,添加到你的 ~/.gitconfig
[alias]
publish-branch = !git push -u origin $(git rev-parse --abbrev-ref HEAD)
你只是跑
git publish-branch
而且......它出版了分支。
我只是做
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
因此,您目前的本地分支机构现在跟踪起源/本地分支。