git多分支和多remote分支以及对应的问题

2012-12-24 20:52:25 +08:00
 lovejoy
我本地有2个分支master lovejoy
分别对应1.git 2.git
问题1: 怎么给加上2.git的对应关系,使得在lovejoy下是git push自动push到2.git 上
问题2: 我在家已经有master,怎么把lovejoy加上?
6751 次点击
所在节点    git
6 条回复
clino
2012-12-24 21:06:14 +08:00
1. 你应该是想要把本地的lovejoy push到2.git的master上吧? 那可以这样,本地用git config配置成
[remote "git2"]
url = URL_TO_2.GIT
push = refs/head/lovejoy:refs/head/master
这样之后只要 git push git2 就可以达到这个目的

2. 你应该是通过2.git来获取这个lovejoy吧?那么在家里的git库上
[remote "git2"]
url = URL_TO_2.GIT
pull = refs/head/master:refs/head/lovejoy
这样之后只要 git pull git2 应该也就可以了
binux
2012-12-24 21:07:23 +08:00
git remote系列命令,linux下还是喜欢像楼上那样直接改配置文件。。mac下直接工具
cabbala
2012-12-24 21:08:30 +08:00
哈哈,刚才在Python群中的是你吧。

问题1:http://stackoverflow.com/questions/520650/how-do-you-make-an-existing-git-branch-track-a-remote-branch
问题2: 群中已经回答
lovejoy
2012-12-24 21:34:48 +08:00
搞定了,记录下,公司:
git branch lovejoy
git remote add origin xxx.git (空git)
git branch --set-upstream lovejoy origin/lovejoy
change something
git commit -a -m "test"
家中
git remote add origin xxx.git
git checkout -b lovejoy remotes/orgin/lovejoy
git branch --set-upstream lovejoy origin/lovejoy
git pull

.git/config
https://gist.github.com/4369274
https://gist.github.com/4369271
lovejoy
2012-12-24 21:43:36 +08:00
公司差一步git config --global push.default simple 这样git push git pull都没有问题,不然提示
warning: push.default 未设置,它的默认值将会在 Git 2.0 由 'matching'
修改为 'simple'。若要不再显示本信息并在其默认值改变后维持当前使用习惯,
进行如下设置:

git config --global push.default matching

若要不再显示本信息并从现在开始采用新的使用习惯,设置:

git config --global push.default simple

参见 'git help config' 并查找 'push.default' 以获取更多信息。
('simple' 模式由 Git 1.7.11 版本引入。如果您有时要使用老版本的 Git,
为保持兼容,请用 'current' 代替 'simple' 模式)
没有提示的应该不需要写。
yoyicue
2012-12-25 10:22:14 +08:00
@cabbala 233

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/55729

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX