git 如何将本地 master 拉入本地分支

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/39598875/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 12:17:41  来源:igfitidea点击:

How to pull local master into local branch

gitgithub

提问by Stophface

I have a remote origin/masterand a remote branch remote_branch. I also have local masterand a local branch local_branch. When I try to pull the local masterinto the local_branchwith git pull master local_branchI get this.

我有一个远程origin/master和一个远程分支remote_branch。我也有本地master和本地分支local_branch。当我尝试将本地拉masterlocal_branchwith 时,git pull master local_branch我得到了这个。

fatal: 'master' 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.

However, when I do git branchI see this:

但是,当我这样做时,git branch我看到了:

* loca_branch
  master

Why can't I pull from my local master?

为什么我不能从我的本地拉master

回答by SantiG

merge changes from local_branch TOmaster

将 local_branch 的更改合并master

git checkout master
git merge local_branch

merge changes from master TOlocal_branch

合并从 masterlocal_branch 的更改

git checkout local_branch
git merge master

Pull is when you have an 'origin' repo :)

拉是当你有一个“原点”repo 时 :)

回答by Shmulik Klein

git pullis an alias for git fetch && git mergeyou cannot fetch from local branches (only from remotes) - actually you don't need to, if your intention is to merge masterinto local_branch, just use git merge masterwhen you are on local_branch.

git pull是一个别名,因为git fetch && git merge您无法从本地分支(仅从远程)获取 - 实际上您不需要,如果您打算合并masterlocal_branch,只需git merge master在您打开时使用local_branch

回答by Vampire

As the error message says, masteris not a repository it knows of. This is because with git pull master local_branchyou say "Fetch the branch local_branchfrom remote repository masterand merge it into my currently checked-out branch".

正如错误消息所说,master不是它知道的存储库。这是因为git pull master local_branch您说“local_branch从远程存储库中获取分支master并将其合并到我当前签出的分支中”。

But that is not what you are after. You want to say "Merge my local branch masterinto my local branch local_branch, checking it out if it is not already" and that would be git checkout local_branch && git merge master

但这不是你所追求的。您想说“将我的本地分支合并master到我的本地分支local_branch,如果尚未合并,请检查它”,那就是git checkout local_branch && git merge master