Whether you’re building your own blog or doing some API development, there’s always code management. Github, Gitee, etc are the most popular code management tools in the market, but since we have our own cloud server, why not build a Git server of our own?

Create a Git user on the server

You can log in to the cloud host using PuTTY, the cloud server management tool. Create a.ssh folder for this user. Git is connected via SSH.

$ sudo adduser git
$ su git
$ cd
$ mkdir .ssh && chmod 700 .ssh
$ touch .ssh/authorized_keys && chmod 600 .ssh/authorized_keys
Copy the code

Add a local public key to the server

Similar to Github, you need to submit the local public key to the Git server. The Windows operating system can use PuTTY to generate a public key

SSH /authorized_keys copy the public key generated by PuTTY to. SSH /authorized_keys, similar to submitting the public key to Github.

Initialize the server Git repo

Create a folder called project under your new Git user and put all your repOs in it. Go to Project and initialize our repO.

mkdir project
cd project
mkdir my-repo
cd my-repo
git init --bare
Copy the code

Push the local REPO to the server

Now that the Git server is set up, you need to push your local REPO onto the server. Go to the directory where the code resides and execute:

$ git init
$ git add .
$ git commit -m 'Initial commit'
$ git remote add origin git@your-server-ip:/home/git/project/my-repo
$ git push origin master
Copy the code

conclusion

Git server can not only manage our code, but also back up important data. A cloud server multi-purpose, full use up!