简体   繁体   中英

Can I checkout branch from local git mirror clone

I have cloned my repo using --mirror flag, can I checkout branch from it if yes how? if no why?

git branch shows me list of all branches but git checkout branch-name gives me error saying:
fatal: This operation must be run in a work tree

Referring to the official docs :

--mirror

Set up a mirror of the source repository. This implies --bare . Compared to --bare , --mirror not only maps local branches of the source to local branches of the target, it maps all refs (including remote-tracking branches, notes etc.) and sets up a refspec configuration such that all these refs are overwritten by a git remote update in the target repository.

Cloning with the --mirror option you are implicitly using the --bare option, which create a repository without a working tree.
The --bare option is used mainly at server-side or in specific use cases.

In your case you shouldn't directly use your mirrored repo, as not having a working tree, is not suitable for editing files or for git commands as git checkout . You should git clone your-mirrored-repo (without the --bare / --mirror option) to have a full working tree, started from the mirrored repo, in which you can use all the git commands or edit files directly.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM