If you are an open source author on GitHub, are you struggling with slow access to GitHub or images that don’t show up? Do you want your code to be seen by more people? Then, you can submit a set of open source code to multiple open source platforms simultaneously.

Of course, if you already do this, but just manually copy and upload separately, then this article is worth a look.

preface

GitHub is a must-visit site for almost every programmer, but one obvious problem with accessing GitHub is that the Internet speed is slow, and many of the images on GitHub are still not displayed properly.

Gitee (code cloud) has been developing rapidly in China in recent years. Let’s take a set of code submitted to GitHub and Gitee as an example to explain how to configure Git to upload code to multiple platforms at the same time.

Create a repository on GitHub

Create a repository on GitHub:

Of course, you can skip this step if the corresponding repository already exists. I already have a repository on GitHub, and this is just an example.

Create the corresponding repository on Gitee

Create a repository on Gitee, preferably with the same name:

After filling in necessary information, select Import existing repository in the bottom column, copy the repository address (in Https format) from GitHub, and paste it in the corresponding location. Gitee detects and prompts.

Click Create and wait for a moment to see that the repository has been perfectly synchronized:

I have a warehouse address for Shiro: gitee.com/secbro/shir… . Not only did the syncing come in, but images that couldn’t be seen on GitHub popped up.

From this point on, your open source project has easily doubled in visibility, isn’t it easy and rewarding?

Manual update synchronization

After the above steps, you have completed the synchronization of the library, but do you notice that when you submit code to GitHub, Gitee does not synchronize the changes to the code?

In this case, there are two methods. The first method is manual synchronization. When the code on GitHub is updated, log in to Gitee and click on the icon in the project name to force the update:

This operation is suitable for non-real-time synchronization. You may log in to your account once in a while to perform synchronization.

Git Commit synchronization

The second way is to submit multiple repositories synchronously with Git. Here, the Mac operating system is used as an example to find relevant commands and operations for other operating systems.

First, clone the GitHub repository locally, for example by executing the following command:

git clone [email protected]:secbr/shiro.git
Copy the code

Then go to the root directory of your local project, where you will find a hidden.git directory.

192:shiro zzs$ ls .git
COMMIT_EDITMSG	ORIG_HEAD	description	info		packed-refs
FETCH_HEAD	branches	hooks		logs		refs
HEAD		config		index		objects
Copy the code

Find the config file under.git and modify it by using vi command. The initial file contents are as follows:

[core]
        repositoryformatversion = 0
        filemode = true
        bare = false
        logallrefupdates = true
        ignorecase = true
        precomposeunicode = true
[remote "origin"]
        url = [email protected]:secbr/shiro.git
        fetch = +refs/heads/*:refs/remotes/origin/*
[branch "main"]
        remote = origin
        merge = refs/heads/main
Copy the code

After modification, it becomes:

[core] repositoryformatversion = 0 filemode = true bare = false logallrefupdates = true ignorecase = true Precomposeunicode = true [remote "origin"] / / lot warehouse address url = [email protected]: secbr/shiro git url = / / gitee warehouse address [email protected]:secbro/shiro.git fetch = +refs/heads/*:refs/remotes/origin/* [branch "main"] remote = origin merge = refs/heads/mainCopy the code

That is, add a URL configuration under the original Github repository address that points to gitee’s address.

Of course, there is a prerequisite that the public and private keys of Gitee and GitHub accounts are the same.

At this point, modify the local code, commit, and you’ll find that the code on GitHub and Gitee has been changed at the same time. Isn’t it cool?

summary

A lot of times, we use “fake diligence” to numb ourselves to look like we’re working hard. For example, when encountering the above synchronization code problem, if you don’t go into the in-depth study, just move the code in the form of manual, although it looks very diligent, but not as good as a line of configuration, a line of command.

Of course, the above example only synchronizes code from GitHub and Gitee repositories, but you can also synchronize code from GitLab, Bitbucket, or your own Git server in the same way.

However, it is recommended to do not exceed two according to the specific situation, otherwise it may take a long time to submit to the warehouse due to network reasons.


Program new horizon

\

The public account “program new vision”, a platform for simultaneous improvement of soft power and hard technology, provides massive information

\