配置本地分支以推送到特定分支
抱歉,如果这个问题已经被问过。
我从名为“git_lab”的存储库进行克隆,该存储库有一个名为“test”的分支 克隆时,我使用“-b myname_test”创建一个名为“myname_test”的本地分支,本地克隆名为“myname_git_lab”
当我执行“git pull”时,它会自动获取并合并从“test”到“myname_test”的更改,但对于git push,我需要指定存储库和分支名称。
$>git remote show git_lab
为“git pull”配置的本地分支: myname_test 与远程测试合并
有没有一种方法可以配置“为‘git Push’配置的本地分支”,这样我就不需要指定分支和存储库名称?
Sorry if this question has been asked already.
Am cloning from a repo named "git_lab" which has a branch named "test"
When cloning i use "-b myname_test" to create a local branch named "myname_test" and local clone is named "myname_git_lab"
When i do "git pull" it automatically fetches and merges changes from "test" to "myname_test", but for git push, i need to specify the repo and branch name.
$>git remote show git_lab
Local branch configured for 'git pull':
myname_test merges with remote test
Is there a way where i can configure "local branch configured for 'git push'" so that i dont need to specify the branch and repo name?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以在这里做两件事。
将
push.default
设置为tracking
,这样它将把所有分支推送到它们跟踪的远程分支,而不是它们同名的分支,然后配置您的分支机构并提供适当的跟踪信息。 (例如将branch.master.remote
设置为origin
并将branch.master.merge
设置为refs/heads/foo
.)手动推动。
git push origin master:foo
会将本地master
分支推送到远程origin
上的分支foo
。< /p>不过,我建议您真正想做的只是使分支名称相同。
(您可以使用
git config
设置配置参数,例如git config push.defaulttracking
,或直接编辑.git/config文件。)There are two things you can do here.
Set
push.default
totracking
, so that it will push all branches to the remote branches they track, not the ones they have the same name as, then configure your branch with appropriate tracking information. (e.g. setbranch.master.remote
toorigin
andbranch.master.merge
torefs/heads/foo
.)Push manually.
git push origin master:foo
will push your localmaster
branch to the branchfoo
on the remoteorigin
.However, I'd suggest that what you really want to do is just make the branch names the same.
(You can set config parameters either with
git config
, e.g.git config push.default tracking
, or by directly editing the .git/config file.)或者,您可以编辑 .git 文件夹中的配置文件。
Alternatively, you can edit the config file in the .git folder.