简体   繁体   中英

How to set up local repo to have different root directory than remote “upstream” directory of an open source project?

I'm trying to set up a Git repo for a personal project I'm working on that will use the Opencart software as a foundation. The Opencart project is hosted on Github at github.com/Opencart/Opencart, so obviously it's using Git as it's version control tool.

I'd like to have the Opencart project as a remote repo (upstream) and keep the Master branch of the Upstream Repo in my local repo to merge future commits into my working copy. The main problem I'm coming across is that the Opencart/Opencart Repo is set up so all the source files are kept in a directory called "upload", but I'd like to keep all the files in the repo directory so I can deploy my repo to my web server's root (public_html) directory. If I set up my Repo to have all the files in the repo root, when I try to merge in commits from the upstream repo it basically duplicates ALL the files except in a directory inside the repo called "upload".

Is there a way to set up/configure my repo so that all my files can be in the repo root directory and have the upstream-master branch keep the files in the "upload" directory but have git consider the two directories the same? That way I can then merge commits from the upstream master into my Repo for future changes/fixes/improvements without Git thinking the there are two sets of files?

Broadly speaking, No . Git does not allow you to have two different view of the same repository that have different directory structures.

Solution 1: Ignore git altogether for uploading

That said, I think you don't need this anyway. If your webhost provides public_html , why not just scp the files you want to the location you want?

You could make this a task in a Makefile/Rakefile/whatever and then run it from your local machine when you want to upload, for example, a makefile task could look like:

upload:
  scp -r ./upload/* me@myhost:/home/me/public_html/

.PHONY: upload

Solution 2: link into your git directory on your webhost

Instead of manually uploading your files, simply link your public_html directory to your upload directory in your git repository on your server. For example:

➤ pwd
/home/me/
➤ find ./
./my_repo.git/
./my_repo.git/upload/
[...]
➤ ln -s ./my_repo.git/upload ./public_html

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