Git doesn't clone all branches on subsequent clones?

前端 未结 4 1744
攒了一身酷
攒了一身酷 2020-12-06 07:54

I have some problems with Git using cloned repositories and branches and it\'s somehow not possible for me to find an answer to this. Let me describe: we have a bare master

相关标签:
4条回答
  • 2020-12-06 07:59

    "origin" is the default name given to the place you cloned the repo from, which is automatically added as a remote (note: remote just means "a repo not the current one" - remotes can be on the same machine).

    In patches, "origin" refers to the original repo on gollum.

    In patches2, "origin" refers to patches.

    Remote tracking refs (the ones that begin with remotes/) are not actually local branches - they're just pointers to where branches were last known to be on the remote. Thus, in patches, you have remote tracking refs for the original repo, but on patches2, you only have a remote tracking ref for the local master branch in patches, because that's where patches2's origin points to.

    You can use git remote add to add the original repo as another remote in patches2 after cloning it - or you could just clone again from the original repo instead of from patches.

    0 讨论(0)
  • 2020-12-06 08:19

    In addition to @ThiefMaster:

    I like to

    git clone --mirror
    

    or

    git push --mirror 
    

    to update all (local & remote) branch refs and tags

    Additional info As noted, --mirror will really replicate the repo as is, thus overwritany changes in the destination. Branches that do not exist in the source will get pruned unconditionally.

    Essentially, it is like working with a remote and doing 'git remote update --prune', the difference being that the branches affected can be local branches as well as 'remote' refs[1]

    @LeSpocky (and others?)

    Now if changes disappear, they will never generate merge problems, so that's easy.

    --mirror is named after the real-life concept, so it was designed to pave over any differences in the target. If the target is non-bare, and you had local changes committed, you can always get them back via the reflog of the target's local branch (git log -g, git reflog).

    As a general safety measure you could have a hook to 'git stash save' in the target.

    Keep in mind though, that --mirror was designed to, well, mirror and this question was in fact on how to replicate all branches to a bare remote. :)

    [1] (the refs are there, but the remote definitions don't get copied; if you want that, do a manual copy from .git/config to .git/config on the push destination)

    0 讨论(0)
  • 2020-12-06 08:21

    See How to clone all remote branches in Git?

    You need to create a local branch based on the remote branch if you actually want it to be included in a clone. However, since you don't work in remote branches anyway you'll create local branches as soon as you start working on a branch. And before that you don't really need it in your clone since you can simply fetch it from remote at any point.

    However, if the notebook has no network connectivity, you'll have to create local branches for all remote branches you want so they are cloned when cloning your local repo.

    If you do have network connectivity however, use git remote add origin2 ssh://adahl@gollum//net/repos/netcube/patches.git and then git fetch origin2 - feel free to replace origin2 with a more meaningful name.

    0 讨论(0)
  • 2020-12-06 08:21
    $ git remote update
    $ git pull --all
    
    0 讨论(0)
提交回复
热议问题