primers

Taking advantage of baidu Cloud 250 cheap to buy two years of server, just build a personal Git warehouse, save the two computers back and forth plug U disk. In fact, very simple, but not very skilled I, or tinkering for a while, by the way, write down the process, save after their own forget. The process screenshots are gone because the setup is complete…

Write as much as you can, because I’m sure I’ll run into a Linux nerd like me. I didn’t use Linux before I bought a server, and the first time I went in, what the hell is that? All command line, no way to start ha ha. So we installed the graphical interface first.

One Ubuntu server as git repository is Ubuntu 16, and two Windows 10 computers are uploaded.

Install git

sudo apt-get install git

Create a new user and manage the Git service

sudo adduser git

The new user created here is called Git

Install OpenSSH

sudo apt-get install openssh-server

Configure SSH password-free login

Modify the /etc/hosts file: add the IP address of the computer from which you want to upload the code

Generate the key on the client

Install Git on both of my Windows PCS and run ssh-keygen -t rsa

Then in C:\Users\ your current user \. SSH, find the id_rsa and id_rsa.pub files; Id_rsa. pub is the public key and we need to copy this file to the server

Use Xftp to copy files to the server, wherever you like, assuming we just copy to /home/git

The usage of Xftp is as follows: Set the protocol to SFTP and keep the port number unchanged

Add the client key to the server

  1. SSH: authorized_kesys: authorized_kesys: authorized_kesys: authorized_kesys: authorized_kesys: authorized_kesys: authorized_kesys: authorized_kesys: authorized_kesys: authorized_kesys

  2. Then add the contents of id_RSA. pub to the authorized_kesys file; Can copy and paste directly, can also use the command: cat/home/git/id_rsa pub > > / home/git /. SSH/authorized_keys; Multiple keys are added one by one, not overwritten

  3. If, like me, you have more than one computer with the same public key file name, either change the name when you create it or delete each one because we need to write the public key into the authorized_keys file

Creating a Git repository

  1. Create a git repository directory, commandmkdir /home/GitServer/wx/Arbitrary address
  2. Initialize the warehouse,Git init - bare/home/GitServer wx/demo. Git
  3. Modify permissions,chown -R git:git /home/GitServer/wx/demo.git. If we don’t do that, then we can’t push
  4. We’re done on the server
  5. Clone the project on the client side.git clone git@baiduyun:/home/GitServer/wx/demo.git, the baiduyun I wrote here was added in the hosts file of my own computer, eliminating the problem of not remembering IP. Hosts file is stored in C:\Windows\System32\drivers\etc

The client uploads the code

Create a Git project

Execute git init in your existing project directory

Add all files to the project

git add .

Git commit -m

Associated remote warehouse

git remote add origin git@baiduyun:/home/GitServer/wx/demo.git

Push all content from the local library to the remote library

git push -u origin master

Git push git push git push git push git push git push git push git push git push git Git will not only push the contents of the local master branch to the new remote master branch, but also associate the local master branch with the remote master branch, which can simplify the command in the future push or pull.

Do ~

When you do, clone the code on another computer and see if you can take the project off the first computer

git clone git@baiduyun:/home/GitServer/wx/demo.git

Refer to the article

  • Set up Git server on Ubuntu
  • Set up Git server (Ubuntu VIRTUAL machine) and Windows client
  • Liao Xuefeng: Set up git server