Remedy for Git multi remote warehouse out of sync

git local warehouse can be associated with multiple remote warehouses. If you want to know how to configure it, please refer to How Git manages code using multiple managed platforms .

When git remote is associated with multiple remote warehouses, there are always some problems. Today, there are two remote warehouses that are inconsistent and cannot be push ed.

Differences between remote warehouses

I am a local warehouse associated with github and gitee.

git remote add all git@github.com:cumt-robin/BlogFrontEnd.git
git remote set-url --add all git@gitee.com:tusi/BlogFrontEnd.git

Due to the manual modification of README.md file on gitee, the two remote warehouses are different. So when I finished some functions locally and prepared to submit to the remote warehouse, there was an error.

$ git push all --all
Everything up-to-date
To gitee.com:tusi/BlogFrontEnd.git
 ! [rejected]        master -> master (fetch first)
error: failed to push some refs to 'git@gitee.com:tusi/BlogFrontEnd.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.

Solution

Because the warehouse of gitee has modified a little more, a remote is added locally to associate with gitee separately.

$ git remote add gitee git@gitee.com:tusi/BlogFrontEnd.git

Pull gitee's code to the local master.

$ git pull gitee master
remote: Enumerating objects: 1, done.
remote: Counting objects: 100% (1/1), done.
remote: Total 1 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (1/1), done.
From gitee.com:tusi/BlogFrontEnd
 * branch            master     -> FETCH_HEAD
 * [new branch]      master     -> gitee/master
Already up to date!
Merge made by the 'recursive' strategy.

Then push the local master to the remote all.

$ git push all --all
Enumerating objects: 2, done.
Counting objects: 100% (2/2), done.
Delta compression using up to 6 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (2/2), 499 bytes | 499.00 KiB/s, done.
Total 2 (delta 0), reused 0 (delta 0)
To github.com:cumt-robin/BlogFrontEnd.git
   1557ece..8391333  master -> master
Enumerating objects: 2, done.
Counting objects: 100% (2/2), done.
Delta compression using up to 6 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (2/2), 917 bytes | 917.00 KiB/s, done.
Total 2 (delta 0), reused 0 (delta 0)
remote: Powered By Gitee.com
To gitee.com:tusi/BlogFrontEnd.git
   8912ff5..8391333  master -> master

The problem is solved!

First link

Scan the applet code below or search Tusi blog, and read the latest articles now!

Keywords: Programming git github

Added by edg322 on Tue, 19 Nov 2019 20:03:36 +0200