admin管理员组

文章数量:1410717

My remote repository has hundreds of branches, so fetch is configured conservatively:

 % git config --get-all remote.origin.fetch
+refs/heads/master:refs/remotes/origin/master
refs/heads/release/2.5:refs/remotes/origin/release/2.5

When I'm trying to work with a new remote branch, argumentless pull does not work:

 % git status
On branch platform_4.33
nothing to commit, working tree clean
 % git pull --set-upstream origin platform_4.33
From github:eclipse-rcptt/.eclipse.rcptt
 * branch                platform_4.33 -> FETCH_HEAD
Already up to date.
 % git pull
Your configuration specifies to merge with the ref 'refs/heads/platform_4.33'
from the remote, but no such ref was fetched.

I can complete the configuration manually:

 % git config --add remote.origin.fetch +refs/heads/platform_4.33:refs/remotes/origin/platform_4.33
 % git pull
From github:eclipse-rcptt/.eclipse.rcptt
 * [new branch]          platform_4.33 -> origin/platform_4.33
Already up to date.

git config is cumbersome, error prone and requires manual pruning once branch is deleted. I do not care about "Remote Tracking Branches", remote.origin.fetch would be empty if it did not break git pull.

How can I configure git pull (without arguments) with fewer or with simpler commands?

My remote repository has hundreds of branches, so fetch is configured conservatively:

 % git config --get-all remote.origin.fetch
+refs/heads/master:refs/remotes/origin/master
refs/heads/release/2.5:refs/remotes/origin/release/2.5

When I'm trying to work with a new remote branch, argumentless pull does not work:

 % git status
On branch platform_4.33
nothing to commit, working tree clean
 % git pull --set-upstream origin platform_4.33
From github:eclipse-rcptt/.eclipse.rcptt
 * branch                platform_4.33 -> FETCH_HEAD
Already up to date.
 % git pull
Your configuration specifies to merge with the ref 'refs/heads/platform_4.33'
from the remote, but no such ref was fetched.

I can complete the configuration manually:

 % git config --add remote.origin.fetch +refs/heads/platform_4.33:refs/remotes/origin/platform_4.33
 % git pull
From github:eclipse-rcptt/.eclipse.rcptt
 * [new branch]          platform_4.33 -> origin/platform_4.33
Already up to date.

git config is cumbersome, error prone and requires manual pruning once branch is deleted. I do not care about "Remote Tracking Branches", remote.origin.fetch would be empty if it did not break git pull.

How can I configure git pull (without arguments) with fewer or with simpler commands?

Share Improve this question edited Mar 5 at 20:58 Basilevs asked Mar 5 at 20:15 BasilevsBasilevs 24.2k16 gold badges60 silver badges106 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 2

Your Git fetch configuration only pulls specific branches, so new ones aren’t fetched automatically.

To fix this, run git fetch --all before checking out a new branch git checkout --track origin/platform_4.33

or

change remote.origin.fetch to get all branches git config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*"

Workaround

git pull does not need remote.origin.fetch setting. It can be removed.

git config --unset-all remote.origin.fetch
git pull --set-upstream origin platform_4.33
git pull # Works as expected

With this configuration no extra branches are fetched and git pull properly handles "--set-upstream".

remote.origin.fetch setting is needed for git maintenance run --task prefetch and probably other activities, but I do not use prefetch or remote tracking branches, so this approach works for me.

I still have no idea why additive configuration is breaking things.

本文标签: git fetchA simple command to configure git pullStack Overflow