配置本地分支以推送到特定分支 [英] Configure a local branch for push to specific branch

查看:107
本文介绍了配置本地分支以推送到特定分支的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从名为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 to tracking, 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. set branch.master.remote to origin and branch.master.merge to refs/heads/foo.)

  • Push manually. git push origin master:foo will push your local master branch to the branch foo on the remote origin.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆