search

Home  >  Q&A  >  body text

git - whichever branch you switch to, will the code of that branch be downloaded locally?

Which branch you switch to, will the code of that branch be downloaded locally?

为情所困为情所困2812 days ago794

reply all(6)I'll reply

  • PHPz

    PHPz2017-05-02 09:35:50

    If everyone is collaborating together, others may have pushed other branches to the central warehouse, but you will not be able to see them locally at this time.
    For example, it turned out to be only the master分支,另外一个人推送了f1 branch.
    This time in your local area,

    λ git branch -a
    * master
      remotes/origin/HEAD -> origin/master
      remotes/origin/master

    Directly execute the switch branch to f1,

    λ git checkout f1
    error: pathspec 'f1' did not match any file(s) known to git.

    Of course it’s not possible.
    So what should you do?

    You can remove the central branch information

    λ git fetch origin
    remote: Counting objects: 3, done.
    remote: Compressing objects: 100% (2/2), done.
    remote: Total 3 (delta 1), reused 0 (delta 0)
    Unpacking objects: 100% (3/3), done.
    From https://git.coding.net/xxx/xxx
     * [new branch]      f1         -> origin/f1
    
    λ git branch -a
    * master
      remotes/origin/HEAD -> origin/master
      remotes/origin/f1
      remotes/origin/master

    This way you can switch branches happily

    λ git checkout f1
    Branch f1 set up to track remote branch f1 from origin.
    Switched to a new branch 'f1'

    You are already branching in f1 at this time,

    λ git branch -a
    * f1
      master
      remotes/origin/HEAD -> origin/master
      remotes/origin/f1
      remotes/origin/master

    * in front indicates the branch currently pointed to by the local.

    reply
    0
  • PHPz

    PHPz2017-05-02 09:35:50

    It seems yes, you can cut it

    reply
    0
  • 某草草

    某草草2017-05-02 09:35:50

    I’m not sure how the specific code is stored, I haven’t researched it. But switching this function should not download all the code. The local code should be detected first, and then the code that is not available locally should be downloaded. The code that is available locally should not be downloaded. If you observe carefully, when a project has a large amount of code, it takes a lot of time to clone it for the first time, but switching branches is much faster. Although the code and branches remain consistent, it doesn't feel like all the code is re-downloaded every time.

    reply
    0
  • 某草草

    某草草2017-05-02 09:35:50

    Unless your local version is the latest, if not you still need to execute it yourselfgit pull origin 分支 to synchronize to the latest version under the corresponding branch

    reply
    0
  • 伊谢尔伦

    伊谢尔伦2017-05-02 09:35:50

    All the branch codes are available locally. Everyone’s warehouse is a clone of each branch version. They are exactly the same, otherwise they would be called clones.

    reply
    0
  • ringa_lee

    ringa_lee2017-05-02 09:35:50

    After switching branches, you need to pull the latest code from the server

    git pull origin xxx分支名称

    reply
    0
  • Cancelreply