Having a hard time understanding git-fetch

后端 未结 4 697
没有蜡笔的小新
没有蜡笔的小新 2020-11-22 15:43

I am having a hard time understanding the nuances of git-fetch. I understand that doing a fetch, fetches the remote refs into a local tracking branch.

I

4条回答
  •  余生分开走
    2020-11-22 16:11

    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.

提交回复
热议问题