[英]Git push local branch to remote branch's branch
I have remote repository with 2 branches, master and login . 我有2个分支的远程存储库,分别是master和login 。 I want to push local changes to login branch but it's not working. 我想将本地更改推送到登录分支,但是它不起作用。
$ git push origin/login
fatal: 'origin/login' does not appear to be a git repository
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
It says 'origin/login' does not appear to be a git repository, but I have. 它说'origin / login'似乎不是git存储库,但是我有。 What's my problem? 我怎么了
$ git log
commit f385d950a1f8c6412d91b26d749282d1a3ead27a (HEAD -> upstream, login, develop)
Author: SoojungChae <naan_ace@naver.com>
Date: Sat Nov 3 06:49:16 2018 +0900
Edit login logic
commit 6719685fbc7f895a909e2515753c02794591595e (origin/login)
Author: SoojungChae <naan_ace@naver.com>
Date: Sat Sep 22 23:43:57 2018 +0900
Block unnecessary things
...
git push
takes two additional arguments: git push
需要另外两个参数:
origin
遥控器的名称,例如origin
master
or login
分支的名称,例如master
或login
That is, you want: 也就是说,您想要:
git push origin login
It's important to keep these two concepts separate: a remote like origin
is a short name that you and Git use to keep track of a longer name like https://github.com/some/repo.git
or ssh://git@github.com/some/repo.git
, which is completely different from a branch name . 将这两个概念分开是很重要的:类似远程的 origin
是您和Git用来跟踪诸如https://github.com/some/repo.git
或ssh://git@github.com/some/repo.git
等较长名称的简称。 ssh://git@github.com/some/repo.git
,它与分支名称完全不同。
What makes this confusing is that besides these concepts and terms— remote and branch —there is a third concept, described by a another sequence of words, usually written as remote-tracking branch . 造成这种混乱的原因是,除了这些概念和术语( 远程和分支)之外,还有第三个概念,用另一个单词序列来描述,通常写为远程跟踪分支 。 1 This third concept involves strings of the form origin/master
and origin/login
. 1第三个概念涉及形式为origin/master
和origin/login
字符串。 It can become very confusing as to when you should write origin login
and when you should write origin/login
. 关于何时应该编写origin login
以及何时应该编写origin/login
可能会造成混乱。
The trick would be to consult the documentation, and keep close track of whether it says remote or branch . 诀窍是查阅文档,并密切跟踪它是remote还是branch 。 Unfortunately, the documentation uses neither of those terms, because those are actually special cases of even-more general form. 不幸的是,文档没有使用这两个术语,因为它们实际上是更一般形式的特殊情况。 So the documentation (now, Git 2.19 2 ) says: 因此文档(现在是Git 2.19 2 )说:
git push
[--all
|git push
[--all
|--mirror
|--mirror
|--tags
] [--follow-tags
] [--atomic
] [-n
|--tags
] [--follow-tags
] [--atomic
] [-n
|--dry-run
] [--receive-pack=<git-receive-pack>
] [--repo=<repository>
] [-f
|--dry-run
] [--receive-pack=<git-receive-pack>
] [--repo=<repository>
] [-f
|--force
] [-d
|--force
] [-d
|--delete
] [--prune
] [-v
|--delete
] [--prune
] [-v
|--verbose
] [-u
|--verbose
] [-u
|--set-upstream
] [-o <string>
|--set-upstream
] [-o <string>
|--push-option=<string>
] [--
[no-
]signed
|--push-option=<string>
] [--
[no-
]signed
|--signed=
(true
|false
|if-asked
)] [--force-with-lease
[=<refname>
[:<expect>
]]] [--no-verify
] [<repository>
[<refspec>...
]]--signed=
(true
|false
|if-asked
)] [--force-with-lease
[=<refname>
[:<expect>
]]] [--no-verify
] [<repository>
[<refspec>...
]]
and the two arguments I am talking about here are called the repository and the refspec , rather than the remote and the branch . 我在这里谈论的两个参数称为存储库和refspec ,而不是远程和分支 。 How one is supposed to get through all of that, as a beginner, is not at all clear. 作为一个初学者,如何实现所有这些还不清楚。
(This is a long-winded way of saying that the Git documentation is not so great.) (这是一种长篇大论的说法,即Git文档并不是很好。)
1 I prefer the term remote-tracking name now, because while it has some of the aspects of a branch name, it also has some that are different. 1我现在更喜欢术语“ 远程跟踪名称” ,因为尽管它具有分支名称的某些方面,但也有一些不同之处。 Either way, though, this third concept takes the form shown above. 无论哪种方式,第三个概念都采用上面显示的形式。
2 Older versions of git push
have fewer optional arguments. 2较早版本的git push
具有较少的可选参数。
It looks like you're using the wrong syntax to push. 看来您使用的是错误的语法。 git push
takes a URL, path, or remote as its first argument, and then branches come after that. git push
将URL,路径或远程作为第一个参数,然后在其后进行分支。 So you'd want to type git push origin login
if you wanted to push your current login
branch to the login
branch on origin
. 因此,如果要将当前login
分支推送到origin
上的login
分支,则需要输入git push origin login
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.