配置本地分支以推送到特定分支 [英] Configure a local branch for push to specific branch
问题描述
我从名为git_lab的repo中克隆了一个名为test的分支
克隆我使用-b myname_test创建一个名为myname_test的本地分支,并将本地克隆命名为myname_git_lab。当我做git pull时,它会自动提取并合并从test到myname_test的更改,但对于git push,我需要指定repo和分支名称。
$ b $> git remote show git_lab
为'git pull'配置的本地分支:
myname_test与远程测试合并
有没有办法我可以配置为git push'配置的本地分支,这样我就不需要指定分支和回购的名称了?
你可以在这里做两件事。
-
设置
push.default
到跟踪
,以便它将所有分支推送到它们跟踪的远程分支,而不是那些他们有相同的名字,然后配置您的分支与适当的跟踪信息。 (例如,将branch.master.remote
设置为origin
和branch.master.merge
至
refs / heads / foo
。)
手动推送。
git push origin master:foo
会将本地的master
分支推送到分支foo
原产地。
不过,我建议你真正想要做的只是让分支名称相同。
(您可以使用 git config
来设置配置参数,例如 git config push。默认跟踪
,或直接编辑.git / config文件。)
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?
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.)
这篇关于配置本地分支以推送到特定分支的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!