Note: I don't have admin privilege on GitLab so I can't use mirroring repositories. I need to do via gitlab-ci with git commands.
I have got 2 different repositories. Source repo on GitLab, target repo on Github.
Source gitlab repo contains files like below:
├── A
├── B
├── C
│ ├── 1
│ │ ├── 2
Target github repo contains files like below:
├── D
├── E
├── F
│ ├── Z
│ │ ├── 5
│ │ ├── 6
I want to update the target repo to be exactly the same as the source gitlab repo files hierarchy. If the files in the target repo are different from the source repo, git commands should remove the differences on the target repo. But when I run my git commands I'm getting below result. It's adding all files together in the target repo. I just want to sync gitlab repo with github repo. If we have any differences I would like to delete all this and store files that only coming from the source gitlab repo.
This my result on the target github repo:
├── A
├── B
├── C
│ ├── 1
│ │ ├── 2
├── D
├── E
├── F
│ ├── Z
│ │ ├── 5
│ │ ├── 6
This is my expectation for target repo:
├── A
├── B
├── C
│ ├── 1
│ │ ├── 2
Here is my git commands:
- git config --global user.name "$github_username"
- git config --global user.email ""
- git fetch --all
- git remote add origin2 https://$github_username:$github_token@$github_url
- git fetch --all
- git checkout origin2/main
- git merge origin/main --strategy-option=theirs --allow-unrelated-histories
- git push https://$github_username:$github_token@$github_url HEAD:main
With above git commands, I'm also getting Merge remote-tracking branch 'origin/main' into HEAD
extra commit in each push. I don't also want to see this extra commits. How can I avoid this also and how should I update the commands.