Git construction and branch management

Build a git server

cnetos7 comes with git, if you need other versions, you can install it yourself.

  • Create a git user group and user to run the git service
groupadd git
useradd git -g git
  • Create certificate login

Collect the public keys of all users who need to log in. The public key is located in the id_rsa.pub file, and import our public key into the /home/git/.ssh/authorized_keys file. If there is no such file create it

cd /home/git/
mkdir .ssh
chmod 755 .ssh
touch .ssh/authorized_keys
chmod 644 .ssh/authorized_keys
  • Create and upload keys locally

Premise, the local win has installed git, after git bash enter

ssh-keygen -t rsa

 id_rsa.pub is the public key we want

  • rz upload key to /home/git

server add public key

sudo sh -c "cat id_rsa.pub >> .ssh/authorized_keys"
  • Initialize the Git repository

First, we select a directory as the Git warehouse, assuming it is /home/gitrepo/test.git, enter the command in the /home/gitrepo directory

cd /home
mkdir gitrepo
chown git:git gitrepo/
cd gitrepo

git init --bare test.git

The above command Git creates an empty warehouse, and the Git warehouse on the server usually ends with .git.

warehouse operations

  • Create a new folder git1 on the local win, clone
git clone [email protected]:/home/gitrepo/test.git

You need to modify it to your own Git service ip, so our Git server installation is complete.

  •  push

The first push needs to set the user's email address and name, set it casually

Enter the test folder and create a new text document

git config --global user.email "[email protected]"
git config --global user.name "Your Name"

git add -A
git commit
  • clone again

Create a new folder git2

git clone [email protected]:/home/gitrepo/test.git

The description was successful. 

branch management

  • There is a master branch by default 

  • The master branch has only one file 1.txt 

  • New branch test1
git branch test1
  • git branch view branch

  • Switch to the test1 branch and add a 2.txt file, submit
git checkout test1

在git1/test文件夹下,右键新建一个2.txt

git add -A

git commit

  •  Switch to the master and find that there is still only one 1.txt file, and then merge the branch test1 to the trunk

 

Pit avoidance guide

If you build a gitlab later, you will find that you have to enter the password every time you clone, and the password will not work no matter what you enter, because gitlab will automatically create 5 users including git! !

Then we didn't know the password, which cheated me all afternoon! !

passwd git just change the password! !

Guess you like

Origin blog.csdn.net/qq_38312411/article/details/129427249