git 拉远程分支而不合并

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/50485434/
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-09 05:17:17  来源:igfitidea点击:

pull remote branch without merge

gitgit-pushgit-pull

提问by Carole

I've created a branch b1and I made some changes on it and I push it to the remote repository:

我创建了一个分支,b1并对其进行了一些更改,然后将其推送到远程存储库:

git branch b1
git checkout b1
git add newfile.txt
git commit -m "adding a new file"
git push origin b1

On an other machine which is connected to the remote repository, I tried to pull the branch without merge it with master:

在连接到远程存储库的另一台机器上,我尝试在不与 master 合并的情况下拉取分支:

$git branch
*master
$git pull origin b1
remote: Counting objects: 4, done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 3 (delta 1), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
From sl*******02:/opt/git/projet1
 * branch            b1    -> FETCH_HEAD
Updating fca3b48..1d96ceb
Fast-forward
 newfile.txt |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
 create mode 100644 newfile.txt

$git branch
*master

what I expected:

我的期望:

$git branch
*master
b1

回答by Calumah

You can use git fetch origin b1to only fetch remote branch without merge.

您可以使用git fetch origin b1仅获取远程分支而无需合并。

See : https://git-scm.com/docs/git-fetch

请参阅:https: //git-scm.com/docs/git-fetch

Basically git pullis a shortcut to git fetch && git merge

基本上git pull是捷径git fetch && git merge

Merge execute because you was on master branch, and not your local b1 branch.

合并执行是因为您在 master 分支上,而不是在本地 b1 分支上。

回答by DRC

You want to checkout the remote branch with

你想用

git checkout b1

if you are on a git version < 1.6.6 the way to do that is instead

如果您使用的是 git 版本 < 1.6.6,那么这样做的方法是

git checkout -b b1 origin/b1