简体   繁体   中英

how to sync a “shadow” git repository with a main repository “secretly”

I have a client that I do work for via a git repository. I do not want for him to know that I am partly using another developer. I have therefore created a "shadow" repository, that my developer is using.

How to sync the "shadow" repository with the main repository so that the main repository does not know that this is happening?

  • I cannot merge with a git command, since this will reveal what I really have done.
  • I could copy and paste all files, but that would visible in git that I have deleted all files and replaced with new files with the same name. That does not look good.
  • My client is using bitbucket. I could give the other developer my bitbucket login, but I would want to avoid to do that.
  • What actually work, is that I can open a file in the main repository, delete the content and then paste in the updated code. Then I could commit and it would look is if I had done the work directly in the main repository. But this is time-consuming (and time is something I do not have too much of).

Is there a different way that I could "secretly" copy the content of files from the shadow repository to the main repository? Is there a linux/osx-command I could use that replaces the content of a file without deleting and recreating the file (which I then could use recursively)? Is there a git-command that make this possible without leaving a trail of evidence of what I have actually done?

you can have the same set of local files revisioned by different git repositories, using the command line. Just use the GIT_DIR environment variable. The Git repositories are completely independent, and can track files from the same directory.

rem set Git to use the sub-developer's git repository
set GIT_DIR=/path/to/sub/repository.com

rem verify which repository that you are on
git rev-parse --git-dir

rem pull the sub-developer's latest
git pull

rem merge, commit, change, push, change branches, whatever
rem ... when the code is the way you want it

rem switch to client repository
set GIT_DIR=/path/to/client/repository.com

rem bring main repository up to date
git commit -m"changes brought over from sub-developer"

rem push the updated code to the client repository
git push

this is useful for other development practices, like versioning lab data, local developmental utilities, work logs, and other 'misc' files that seem to accumulate with the source code, but shouldn't be archived with it.

After my error on the first answer, I feel compelled to try again.

try reading in the sub developer branch and comparing/merging to main with git differencing. see 'git help config' for 'diff.external'. I use diffuse.exe and a batch file to map the parameters.

The work flow would look something like this.

rem make a remote to the sub
git remote add MYSUB https://path/to/sub/repository.com

rem see what branches are there
git remote show MYSUB

rem get the branch from the subdeveloper
git fetch MYSUB CurBranch:CurBranch

rem view/manually merge just the modified files 
git diff --diff-filter=M MYSUB/CurBranch 

rem cleanup
git branch -D MYSUB/CurBranch
git rm MYSUB

rem push to main site
git push

This is the method I use to transfer branches to my lab machine, via a USB memory stick. I have not tried it with a remote connection.

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