pull remote branch without merge

Carole picture Carole · May 23, 2018 · Viewed 40.5k times · Source

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

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:

$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

Answer

Calumah picture Calumah · May 23, 2018

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

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

Basically git pull is a shortcut to git fetch && git merge

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