Git:如何在存储库之间移动分支 [英] Git: how to move a branch between repositories

查看:169
本文介绍了Git:如何在存储库之间移动分支的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的情况:我从存储库中克隆了一个主分支,并创建了一个本地分支来进行更改。经过几天的工作,我试图推动我创建的本地分公司,所以团队也可以开展工作。然后我意识到我没有权限推送到这个存储库,所以我创建了一个fork和一个分支,这样我就可以推送我的更改。



现在我想要把这个分支移到我的叉子上并保存在同一个地方。真正理想的情况是将此分支指向现有位置。



我正在使用sourcetree和bitbucket



感谢您的帮助

解决方案

Git是一个分布式版本控制系统。所以你可以在多个地方有相同的回购。当你第一次在本地克隆一个回购站时,你可以使用一个名为origin的远程设备(参见输入 git remote -v )。您只需添加您创建的第二个分支作为第二个分支:



git remote添加其他git@host.com:foo / bar。 git



other只是远程名称,所以后面你可以这样做: git push other master (将我的本地主人推送给其他人的主人)或 git push other local_branch:remote_branch



可能性无穷无尽,您可以从任何远程分支机构向任何当地分支机构推送/推送。

Git在他们的网站上免费提供了一本书: https://git-scm.com/book/en/v2 。这对每个人来说都是一个很好的开始,这对我来说是一段时间了。

Here is my situation: I have cloned a master branch from a repository and created a local branch to make the changes. After a few days working I tried to push this local branch I have created so the team could also work on it. Then I realized that I don't have the permission to push to this repository, so I created a fork and a branch so I can push my changes.

Now I want to move this branch to my fork and keep it saved in the same place. The really ideal scenario would be just point this fork branch to the exiting location.

I'm using sourcetree and bitbucket

How can I do that?

Thanks for any help

解决方案

Git is a distributed version control system. So you can have the same repo in multiple locations. When you first clone a repo locally, you have your own copy with a "remote" called origin (see it typing git remote -v). You simply need to add the second fork you created as a second remote:

git remote add other git@host.com:foo/bar.git

"other" is just a name for the remote, so later you can do: git push other master (push my local master to other's master) or git push other local_branch:remote_branch

The possibilities are endless, you can pull/push from any remote's branches to any local branches.

Git has a book available for free hosted on their site: https://git-scm.com/book/en/v2. It's a great start for everyone, it was for me a while back.

这篇关于Git:如何在存储库之间移动分支的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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