简体   繁体   English

如何将我的分支推送到主存储库?

[英]How to push my branch to master repository?

I am developing code in my (private) repository on branch 'my_branch'. 我在分支“ my_branch”的(专用)存储库中开发代码。

After some development I am happy with what I have done and I would like to save 'my_branch' to master repository (so it will not get lost in case my disk has a fault). 经过一些开发后,我对自己所做的事情感到满意,并且我想将“ my_branch”保存到主存储库中(因此,如果我的磁盘出现故障,它不会丢失)。

But I don't want to merge my changes to master branch yet. 但是我还不想将更改合并到master分支中。

I used command: 我使用命令:

git push git推

and then: 接着:

got clone 得到克隆

and cloned master repository to a different directory. 并将主存储库克隆到其他目录。 But I noticed that on that directory when I change to my_branch the files do not contain my changes. 但是我注意到在该目录上,当我更改为my_branch时,文件不包含我的更改。

Please help! 请帮忙!

(It seems to me that everyone normally works in similar way: from time to time backing up your branch whilst not yet merging it to master?) (在我看来,每个人通常都以类似的方式工作:不时备份您的分支,而尚未将其合并到母版中?)

I used to work in ClearCase and what is good about it is: as soon as you check-in your file in your private branch, it can never get deleted, but from the other hand it is not on main branch and you can continue developing your code without disturbing other developers. 我曾经在ClearCase工作过,它的优点是:一旦您在私有分支中签入文件,它就永远不会被删除,但是另一方面,它不在main分支中,您可以继续开发您的代码而不会打扰其他开发人员。

You can push your branch to an upstream repo (which isn't called "master", but "origin" by default: git push origin myBranch ), but when you clone, you clone by default the master branch, not myBranch . 您可以将分支推送到上游存储库(默认情况下不称为“ master”,而是“ origin”: git push origin myBranch ),但是在克隆时,默认情况下,您将克隆master分支,而不是myBranch
And your branch isn't tracked by default. 并且默认情况下不会跟踪您的分支。
Ie, you don't have a local branch myBranch on your clone, which track origin/myBranch (the branch fetch from the remote repo). 即,您的克隆上没有本地分支myBranch ,该分支跟踪origin/myBranch (从远程存储库获取的分支)。

On your clone, you need to create a local branch for all the fetched remote branches. 在克隆上,您需要为所有提取的远程分支创建一个本地分支。
See " Track all remote git branches as local branches ". 请参阅“将所有远程git分支跟踪为本地分支 ”。


As I mention in " Sell me Distributed revision control ", branching is orthogonal to publishing (push/pull): 正如我在“ 向我出售分布式修订版本控制 ”中提到的那样,分支与发布(推/拉)正交:

Each time I want to "check-in" changes on my branch - is it enough to call "git push origin my_branch" or "git push my_branch" 每次我想在分支上“签入”更改时,是否足以调用“ git push origin my_branch”或“ git push my_branch”

Any commit is a local one, as opposed to ClearCase (which commits on the LATEST of a centralized branch in a config spec). 与ClearCase(在配置规范中的集中式分支的最新提交)不同,任何提交都是本地提交。
See " What are the basic clearcase concepts every developer should know? " for the differences between ClearCase and Git. 有关ClearCase和Git之间的区别,请参阅“ 每个开发人员应了解的基本Clearcase概念是什么? ”。

So a simple commits remains on your local repo, invisible to all other developers. 因此,简单的提交仍保留在本地存储库上,所有其他开发人员都看不到。
If you push your branch to an upstream repo (see " Definition of “downstream” and “upstream” "), that branch will be cloned by other developers, but they won't see its content unless they checkout that branch in their own local repo. 如果将分支推送到上游仓库(请参阅“ 下游”和“上游”的定义 ”),则该分支将被其他开发人员克隆,但是除非他们在自己的本地签出该分支,否则他们将看不到其内容。回购。
By default, they would see the master branch. 默认情况下,他们将看到master分支。

No "special clone mode" needed: a clone would clone the all repository content, with all its history and branches. 无需“特殊克隆模式”:克隆将克隆所有存储库内容及其所有历史记录和分支。

Run

git push -u origin my_branch

Then in the future you can just run "git push". 然后,将来您可以运行“ git push”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM