简体   繁体   中英

Single Git repo with directories in multiple locations

Git newb question here. Coming from SVN, where I can have multiple branches checked out all of the place ("/www/project1", "/users/project2", etc.) but all live in the same repository. Each branch has it's own commits, revisions, etc. You guys know the deal.

Is there a similar method to this in Git, where you can have directories/branches in a single repo spread out all over place? Again, sorry for the newb question. Trying to get a bead on this. Thanks a bunch for any insight that can be provided here.

Normally, as checkout and merging process are really fast, developers using Git keep all branches and just switch between them in the same folder. The SVN branching system is very slow, and not really good, that's why they usually kept them in a different folder.

It is possible to checkout a branch to a different folder:

git --work-tree=<path to target> --git-dir="<path from source>" checkout <reference-name>
# example:
git --work-tree=. --git-dir="/base-repo/.git" checkout master

Note, though, that this new folder won't be versioned. To keep it versioned, you could re-clone the repo in another folder:

git clone path/to/local/repo/.git

Note that in git, each clone is the full repo (the exact same thing there is on your server and in your other folder). Each clone is completely independent and can push/pull from any other repo.

Hope this helps!

Git is a distributed control version. So, you can have local branches and remote branches. To create local branches, use the command git branch name where name represents your branch name. To see all local branches, you can use the command git branch . It will list all branches and the current branch. To change between local branches, use the command git checkout name where name represents your branch name.

To send the local branch to remote repository, use the command git push origin name where name represents the name of your branch. And to copy a local branch to your computer, use the command git checkout -t origin/name .

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