简体   繁体   English

在另一个分支中是否可以将更改推送到主分支

[英]Is it possible to push changes to master branch while in another branch

While we are working in different branches in git repo is it possible to accidentally push your changes from a branch say demo to master . 当我们在git repo中的不同分支中工作时,可能会无意间将您的更改从一个分支(例如demo)推送到master I do know in order to bring the changes to master branch we have to do a merge the require branch to the master. 我知道为了将更改带到master分支,我们必须将require分支合并到master。

Sometimes when I push to a branch I have these doubt if I'll push it to master accidentally so just to clear that up... 有时候,当我推送到一个分支时,我会怀疑是否会不小心将其推送到主分支,只是为了清除它...

 git push origin  local-branch-name:remote-branch-name

In this case, it should be: 在这种情况下,应为:

 git push origin  demo:master

If you're using gitlab/github, you can set master branch as protected to avoid pushing some branch to master accidentally 如果您使用的是gitlab / github,则可以将master分支设置为protected以避免将某些分支意外推入master

git push origin master 

This pushes any branch you are on to the master branch in the origin repository. 这会将您所在的任何分支推送到原始存储库中的master分支。

the shortcut 捷径

git push

only works, if the current branch is linked to some remote branch via --set-upstream . 仅当当前分支通过--set-upstream链接到某个远程分支时才有效。 For example with 例如与

git push --set-upstream origin master 

Note: There are more ways to set an upstream branch 注意:还有更多设置上游分支的方法


It is perfectly possible to accidentally push to a wrong branch. 完全有可能无意中推到错误的分支。 For example when you were tracking a wrong branch, or because there was a typo in the push-command, or because you forgot what branch you were on. 例如,当您跟踪错误的分支时,或者由于push命令中有错字,或者因为您忘记了所在的分支。

No need to worry 不用担心

Because if you are in other branch you made changes and unfortunately pushed to master 因为如果您在其他分支机构中,则会进行更改并不幸地被迫掌握

Ex: Your in slave branch you pushed to master ( git push orgin master ) 例如:您在从属分支中被推送到主分支( git push orgin master

It will show Everything up-to-date 它将显示所有最新信息

If you push recursively also ( git push -u origin master ) master branch won't affect ( If you are in other branch only ) 如果您也以递归方式推送( git push -u origin master ),master分支将不受影响( 如果您仅在其他分支中

Master branch wont change until unless you merge with other branch's or till changes made in master 除非您与其他分支合并,或者直到在master中进行更改,否则Master分支才会更改

                                      **cool**

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

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