简体   繁体   English

是 Git 提交和 Git 推送分支特定

[英]Is Git commit and Git Push Branch Specific

I'm currently working on a git branch, so I cloned it and started to modify stuff as usual, however if I commit the usual way (git add. -> git commit -m "" -> git push) would it push to the correct branch?我目前正在开发一个 git 分支,所以我克隆了它并开始像往常一样修改东西,但是如果我按照通常的方式提交(git add.-> git commit -m "" -> ZBA9F11ECC3497D9953B933FDC2 推送)正确的分支? or is there a specific command I need to do, I am working on code in production, so I don't accidentally push to the wrong branch或者是否有我需要执行的特定命令,我正在处理生产中的代码,所以我不会不小心推送到错误的分支

Running git branch -vv will show you to which branch git push will push by default.运行git branch -vv将显示默认情况下git push送到哪个分支。 For example, in a local repository on my system, running git branch -vv shows:例如,在我系统上的本地存储库中,运行git branch -vv显示:

$ git branch -vv
* devel              c557af4 [origin/devel: ahead 14, behind 26] Add tests for create_sprint_board
  devel.stgit        f51dcdd goto
  master             4239189 [upstream/master: behind 6] disable create-sprint-boards pending #10
  save/before-squash d5b7980 add tests for create_sprint_board
  work               8bf0290 log warning if --copy-cards and no previous board

Here we see that running git push on the the devel branch will push to the devel branch of the remote named origin , and running git push on the master branch will push to the master branch of the remote named upstream .这里我们看到在devel分支上运行git push会推送到远程origindevel分支,在master分支上运行git push会推送到远程upstreammaster分支。

Other branches -- like work -- don't have a "tracking branch" associated with them yet.其他分支——比如work ——还没有与之关联的“跟踪分支”。 On those branches, running git push will result in:在这些分支上,运行git push将导致:

fatal: The current branch work has no upstream branch.
To push the current branch and set the remote as upstream, use

    git push --set-upstream origin work

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

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