简体   繁体   English

如何将分支推送到远程

[英]How to push branch to remote

I have 2 branches in my local system named A and B . 我的本地系统中有2个分支,分别为AB I checkout to B means now I am in B . 我结账到B意味着我现在在B I wrote some code, commited in that branch itself but I didn't push the branch to remote. 我写了一些代码,提交到该分支本身中,但没有将分支推送到远程。 Now I checkout to A , where I am facing some problems so I want to push B to remote. 现在我结帐到A ,在那里我遇到了一些问题,因此我想将B推到远程。

Is it possible to push from a branch to another branch? 是否可以从一个分支推送到另一个分支?

I am facing this problems in Branch A : 我在分公司A遇到此问题:

  • After checkout from B to A , it shows public/index.html: Permission denied . BA签出后,它显示public/index.html: Permission denied
  • I tried to checkout to B from A but it's not allowing me. 我试图从AB结帐,但不允许我这样做。 It shows the following message: 它显示以下消息:

    error: Your local changes to the following files would be overwritten by checkout: public/index.html Please, commit your changes or stash them before you can switch branches. Aborting error: Your local changes to the following files would be overwritten by checkout: public/index.html Please, commit your changes or stash them before you can switch branches. Aborting . error: Your local changes to the following files would be overwritten by checkout: public/index.html Please, commit your changes or stash them before you can switch branches. Aborting

How not to lose the code that I wrote in branch B ? 如何不丢失我在分支B编写的代码?

做这个:

$ git push origin B:refs/heads/B

Do git push origin the_other_branch_name git push origin the_other_branch_name

It's ok to do it while you working are in another branch with either unstaged or staged files (I just tried it). 当您在另一个具有未暂存或暂存文件的分支中工作时,可以这样做(我刚刚尝试过)。

Before moving on to any other branch, you can either temporarily save them to be able to restore them later ( read stash them ) or commit the changes for that particular branch. 在转到任何其他分支之前,您可以暂时保存它们以便以后还原(读取存储),也可以提交该特定分支的更改。

Your changes will always be safe if you have done any of the above. 如果完成以上任何一项操作,更改将始终是安全的。

I think, here you would want to stash your changes instead of pushing the branch B's changes to the remote. 我认为,在这里您将希望存储更改,而不是将分支机构B的更改推送到远程。

"git stash" is the command for saving all the changes temporarily. “ git stash”是用于临时保存所有更改的命令。 You can restore these changes on any branch. 您可以在任何分支上还原这些更改。

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

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