Skip to content

Commit code from one git repository to anotherIn actual development, branch_a in the repro_a warehouse is independently transformed into a new warehouse repro_b. Mainly relies ongit remotefor implementation.

1. Submit the current code to another remote git repositoryIf warehouse repo_a is currently located in branch_a, it is required to extract all the data of branch_a (including submission history) and create a new warehouse repo_b. It is assumed here that the warehouse repo_b has been created.The basic syntax ofgit remote addis as follows. name and url are required.

git remote add [-t <branch>] [-m <master>] [-f] [--[no-]tags] [--mirror=<fetch|push>] <name> <url>

(1). Add the URL of the warehouse repo_b to the remote of the working warehouse.```

git remote add origin_repo_b git@server_ip:/path/repo_b.git

(origin_repo_b: the name you choose, as long as it does not duplicate the existing remote name)
(git@server_ip:/path/repo_b.git:repo_b’s remote path)
### (2). Push the code to remote repo_b.
git push origin_repo_b branch_a
(origin_repo_b: the name of the remote warehouse repo_b)
(branch_a: branch_a branch of warehouse repo_a)
### (3). Clone the warehouse repo_b and check whether the push is successful.
## 2. Submit the same code to multiple different git hosting servers (multiple git repositories)The method is very similar, mostly using the command`git remote set-url --add [--push] <name> <newurl>`Assume that a new warehouse repo_c is added to the remote git server, and the codes submitted by repo_b and repo_c must be consistent.
### (1). Configure remote repo_c into the current working local git repository
git remote set-url --add origin_repo_b git@192.168.1.101:~/project/repo_c.git
What this sentence means is that the remote warehouse git@192.168.1.101:~/project/repo_c.git is also added to the name origin_repo_b for management.
### (2). Submit the code to remote warehouse repo_b and remote warehouse repo_c at the same time```
git push origin_repo_b branch_a

(3). fatal: refusing to merge unrelated histories```

git pull origin master --allow-unrelated-histories ```

REF[1]. Git-Configuration