git fetch only for current branch

前端 未结 5 1720
刺人心
刺人心 2021-02-14 06:33

I know that I can fetch any remote branch to any local branch, but is there also some kind of shortcut to fetch just from the tracked remote branch to the current tracking local

相关标签:
5条回答
  • 2021-02-14 07:15

    Let's assume that you have origin remote with master, develop branches. You want to sync master but not develop.

    You can do the following steps:

    git fetch origin
    git merge origin/master
    

    UPDATE: in case of only branch have to be fetched:

    git fetch origin master
    git merge FETCH_HEAD
    
    0 讨论(0)
  • 2021-02-14 07:20

    Tying together a few things from the existing answers...

    Get the name of the checked out branch:

    git rev-parse --abbrev-ref HEAD
    

    To answer your question, how do you fetch only the current branch? Here you go, as an alias called fetchthis. Use like git fetchthis.

    git config --global alias.fetchthis '!bname=$(git rev-parse --abbrev-ref HEAD); git fetch origin $bname`
    

    Tested in Git for Windows:

    $ git --version
    git version 2.25.1.windows.1
    
    0 讨论(0)
  • 2021-02-14 07:21
    git fetch $(git rev-parse --symbolic-full-name --abbrev-ref @{upstream} | sed 's!/! !')
    
    0 讨论(0)
  • 2021-02-14 07:29

    Per https://stackoverflow.com/a/12142066/25192 - you can use this to find the name of the current branch:

    git rev-parse --abbrev-ref HEAD

    ...then substitute this into the fetch command as the refspec.

    0 讨论(0)
  • 2021-02-14 07:38

    Git is a decentralized VCS. Whe you do a fetch, you're synch'ing the two repositories entirely. Branches aren't nothing but labels attached on specific commits. I guess you mean git fetch which doesn't do any merges or stuff like that to any particular branches.

    http://www.kernel.org/pub/software/scm/git/docs/git-fetch.html

    0 讨论(0)
提交回复
热议问题