How to push multi repositories in same project

My computer develop environment

1
2
3
4
5
6
7
$ sw_vers
ProductName: Mac OS X
ProductVersion: 10.12.3
BuildVersion: 16D30

$ git --version
git version 2.18.0

I recently created a outsourcing project that needs to submit the project code to empolyer’s github repository,
But i want to save the project in my private repository at the same time, so i thick i can submit it to two repositories
at the same time when i push the git.
Here is my personal code repository gitee.

The first step, create a new repository

It named https://gitee.com/liyuliang/xxxx
Be careful not to check the option Use Readme file to initialize this project (使用Readme文件初始化这个项目)
The first time i checked this option, i got an error when git pushing

1
2
3
4
5
6
7
8
To gitee.com:liyuliang/xxxx.git
! [rejected] master -> master (fetch first)
error: failed to push some refs to '[email protected]:liyuliang/xxxx.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

Second, Add a git repository in your project

1
$ git remote set-url --add origin [email protected]:liyuliang/xxxx.git

The project git config file looks like this

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
$ cat .git/config 
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
ignorecase = true
precomposeunicode = true
[remote "origin"]
fetch = +refs/heads/*:refs/remotes/origin/*
url = [email protected]:liyuliang/xxxx.git
url = [email protected]:liyuliang/xxxx.git
[branch "master"]
remote = origin
merge = refs/heads/master

The Last, push your code to all your repositories

1
$ git push --all
Share