Git 提交和 Git 推送分支特定

Is Git commit and Git Push Branch Specific

我目前正在 git 分支上工作,所以我克隆了它并像往常一样开始修改内容,但是如果我按照通常的方式提交 (git 添加 . -> git commit -m "" -> git push) 它会推送到正确的分支吗?或者是否有我需要执行的特定命令,我正在生产中处理代码,所以我不会不小心推到错误的分支

运行 git branch -vv 将显示 git push 默认推送到哪个分支。例如,在我系统的本地存储库中,运行 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

这里我们看到 devel 分支上的 运行 git push 将推送到远程名为 origindevel 分支,并且 运行 git pushmaster 分支上将推送到名为 upstream.

的远程的 master 分支

其他分支——比如work——还没有与之关联的“跟踪分支”。在这些分支上,运行 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