I have a project under source control at repo 1. I'd like to make it so that when I commit a file, or push a commit, at the same time commit/push the commit to another repo (repo 2). Is this possible? The only potential problem would be since repo 2 would only contain a subset of the files of repo 1, it would be possible that a commit of repo 1 contains files repo 2 does not have. In that case, no commit should be made.
Asked
Active
Viewed 34 times
1
-
Hey @hojoniv, welcome to SO. It would help if you could format the question a bit to make it more readable. – Sid Jan 21 '20 at 05:36
-
Repo two will be getting the intervening change sets if you push to it.. pushing to two would fail if that branch on that remote has something newer than you have. – Grady Player Jan 21 '20 at 13:28
1 Answers
0
You can push to multiple repositories in one command with the configuration set by git remote set-url --add --push
.
But that supposes those repositories have the same history (same commits and files)
In your case, you would need to script your push, in order to:
- compare files between your local clone of repo1 and local clone of repo2
- import those files into repo2
- add, commit and push from local clone of repo2 to remote repo2.
Typically that would be:
cd /path/to/local/clone/of/repo2
git --work-tree=/path/to/repo1 add .
git status # check there is no new files added
# add, commit and push to origin of repo2

VonC
- 1,262,500
- 529
- 4,410
- 5,250