Synchronize native code to gitee and github

Synchronize native code to gitee and github

Today, I'd like to introduce how to use it and push our local warehouse to gitee and github. Now there are two remote warehouses. One is gitee and github remote warehouse. The address corresponds to my local, that is, work space.

The first step is to establish the warehouse address in gitee and github

Register gitee and github directly through the official website

gitee official website https://gitee.com/

github official website https://github.com/

git also needs to be installed locally

The second step is to build a new git warehouse in a local folder

Initialize git in local D:\work\workspace

git init

Then a will be generated in workspace git folder

The third step is to associate the remote warehouse address

1. Add github

Local warehouse workspace, right-click to open gitbsah, and enter the following command

git remote add github git@github.com:xxxx/javaCore.git

2. Add gitee

Local warehouse workspace, right-click to open gitbsah, and enter the following command

 git remote add gitee git@gitee.com:xxx/java-Core.git

The above warehouse address should be filled in according to the actual registration

The fourth step is to modify the current address of the warehouse config configuration of git

Under the folder where git init is executed, open Git, there is a config file to modify the configuration

[core]
    repositoryformatversion = 0
    filemode = true
    bare = false
    logallrefupdates = true
    symlinks = false
    ignorecase = true
[remote "github"]
    url = git@github.com:xxxx/javaCore.git
    fetch = +refs/heads/*:refs/remotes/github/*
[remote "gitee"]
    url = git@gitee.com:xxx/java-Core.git
    fetch = +refs/heads/*:refs/remotes/gitee/*
[branch "master"]
    remote = origin
    merge = refs/heads/master

Change filemode = false to true

Step 5: check the remote warehouse address

Execute the following instructions

git remote -v

You can view the remote warehouse address

$ git remote -v
gitee   git@gitee.com:xxx/java-Core.git (fetch)
gitee   git@gitee.com:xxx/java-Core.git (push)
github  git@github.com:xxx/javaCore.git (fetch)
github  git@github.com:xxx/javaCore.git (push)

The above is the added warehouse address

Step 6: add the key and check whether the key is feasible

1. Generate ssh key

Open cmd in windows system

Execute the following command

ssh-keygen -t rsa -C xxxxxx@qq.com

Then press enter all the way. By default, it will be generated to C: \ users \ Dell \ ssh this address and open it ssh, ID will be generated_ rsa´╝îid_rsa.pub, this pair of public and private keys, the public key id_rsa. Open pub with editor

2. Add ssh key

Add ssh public key to the personal information of gitee and github, log in to your gitee account and github account

3. Check whether the addition is successful

ssh -T git@gitee.com 
ssh -T git@github.com

You've successfully authenticated will appear. You have passed the verification

Step 7: test the submission code

1. Add test file

Create a new test in the local workspace Txt file

2. Push to remote warehouse

git pull gitee master
git pull github master
git add .
git commit -m "test file"
git push gitee master
git push github master

On the remote side, view the file just added

Step 8: summary of common errors

Some pits encountered in this process are summarized below

$ git pull gitee master
From gitee.com:xxx/java-Core
 * branch            master     -> FETCH_HEAD
fatal: refusing to merge unrelated histories


$ git add .

DELL@felix MINGW64 /d/work/workspace (master)
$ git push gitee master
To gitee.com:xxxxx/java-Core.git
 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'gitee.com:xxxx/java-Core.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details



 git pull gitee master
From gitee.com:xxxxx/java-Core
 * branch            master     -> FETCH_HEAD
fatal: refusing to merge unrelated histories

git pull origin master --allow-unrelated-histories
fatal: 'origin' does not appear to be a git repository
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.


git pull gitee  master --allow-unrelated-histories
From gitee.com:xxxx/java-Core
 * branch            master     -> FETCH_HEAD
Merge made by the 'recursive' strategy.
 LICENSE | 201 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 201 insertions(+)
 create mode 100644 LICENSE


 $ git pull gitee master
From gitee.com:xxxxx/java-Core
 * branch            master     -> FETCH_HEAD
Already up to date

Step 9: personal summary

Think about the way you have learned, synchronize the local code to different remote warehouses, with the main purpose of recording learning and mastering skills as the main idea. If you have something wrong to say or do, please correct it. I think you will get different answers in different discussions. Welcome to put forward different voices. Thank you!

Keywords: git github

Added by alexvgtb on Wed, 02 Mar 2022 16:45:58 +0200