Having a hard time understanding git-fetch

First, there’s no such concept of local tracking branches, only remote tracking branches. So origin/master is a remote tracking branch for master in the origin repo.

Typically you do git fetch $remote which updates all your remote tracking branches, and creates new ones if needed.

However, you can also specify a refspec, but that will not touch your remote tracking branches, instead, it will fetch the branch you specified and save it on FETCH_HEAD, unless you specify a destination. In general you don’t want to mess with this.

Finally,

fetch = +refs/heads/*:refs/remotes/origin/*

That means if you do

git fetch origin

It will actually do:

git fetch origin +refs/heads/*:refs/remotes/origin/*

Which means a remote heads/foobar will be local remotes/origin/foobar, and the plus sign means they’ll be updated even if they are not fast-forward.

Perhaps what you think as a tracking branch is something related to git pull and the merge config.

Leave a Comment