Enterprise level automation code release -- Git foundation and introduction

Keywords: git ssh yum github

About Git

Git is a distributed version control system

git vs SVN

project GIT SVN
operation Complex concept, many orders, not easy to use Easy to operate
Branch price Cheap branch Expensive branches
Code management Distributed management Centralized management
preservation Save the full file of the historical version Keep difference file

git core

One of the core concepts of Git is workflow

  • Workspace is the actual directory in the computer
  • The index is similar to the cache area. It temporarily saves your changes
  • Repository, which is divided into local warehouse and remote warehouse

Generally, the code is submitted in three steps:
git add commit from workspace to staging area
git commit from staging area to local warehouse
git push submit from local warehouse to remote warehouse

git installation and configuration

Install git server

#Install yum dependency and software
yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel perl-devel -y
yum install -y git
# Create user groups and users
groupadd git
useradd git -g git
passwd git
# Initialize empty git version Library
[root@git-server ~]# mkdir /home/git/gitrepo
[root@git-server ~]# cd /home/git/gitrepo
[root@git-server gitrepo]# git init --bare runoob.git	#Do not specify. git as the default
[root@git-server gitrepo]# cd ..
[root@git-server git]# chown -R git:git gitrepo
# Clone official warehouse to local warehouse
git clone https://github.com/jenkins-docs/simple-java-maven-app.git

git server configuration

cd /etc/ssh
vim sshd_config
#RSAAuthentication yes
#PubkeyAuthentication yes
#AuthorizedKeysFile .ssh/authorized_keys

systemctl restart sshd
cd /home/git
mkdir .ssh
chown -R git:git .ssh
chmod 700 .ssh
cd .ssh
touch authorized_keys
chmod 600 authorized_keys
chown -R git:git authorized_keys
systemctl restart sshd

Authorized on the server_ Keys write the client's public key ip_rsa.pub

[git@git-server ~]$ git config --global user.name "Kelsey1998"
[git@git-server ~]$ git config --global user.email "1284915257@qq.com"
[git@git-server ~]$ cat .gitconfig
[user]
        name = Kelsey1998
        email = 1284915257@qq.com

Version Library (warehouse) creation

[git@git-server ~]$ mkdir -p workspace/demo
[git@git-server ~]$ cd workspace/demo #work area
[git@git-server dome]$ git init
Initialized empty Git repository in /home/git/workspace/demo/.git/
# View git version Library
[git@git-server demo]$ ls -ld .git
drwxrwxr-x. 7 git git 119 May 30 16:17 .git
Table item catalog
Version Library workspace/demo/.git is also called warehouse
work area The directory where the workspace / demo. Git version library is located

git global file

. gitconfig user personal under the user's home directory
System file / etc/gitconfig Global

git user name and email address

[git@git-server ~]$ git config --global user.name "Kelsey1998"
[git@git-server ~]$ git config --global user.email "1284915257@qq.com"
[git@git-server ~]$ cat .gitconfig
[user]
        name = Kelsey1998
        email = 1284915257@qq.com

The configured user name and email address will be used when the version library is submitted

git alias

[root@git-server ~]# git config --system alias.st status
[root@git-server ~]# git config --system alias.co checkout
[root@git-server ~]# git config --system alias.ci commit
[root@git-server ~]# git config --system alias.br branch
[git@git-server ~]$ cat /etc/gitconfig
[alias]
        st = status
        co = checkout
        ci = commit
        br = branch

git command highlight

[git@git-server ~]$ git config --global color.ui true
[git@git-server ~]$ cat .gitconfig
[user]
        name = Kelsey1998
        email = 1284915257@qq.com
[color]
        ui = true
level Valid directory
Local The current project is valid (working directory /. git/config)
Global The current user is valid (user directory /. gitconfig)
system All users are valid (Git directory / etc/gitconfig)

git command

git status

  • git status
    View the current status of the project
  • git status -s
    --short, the output is marked as two columns. The first column is for staging staging area, and the second column is for workspace workspace
state meaning
? Not added to cache
A Locally added files
M The content or mode of the file has been modified
AM After the file is added to the cache, it needs to be added by git again
D Files deleted locally
R Modify file name

git add

git add add files to cache

git add .	#Add all files for the current project
git add <filename1,filename2>	#Add specified file

git reset HEAD

Git reset head < filename > cancel cached content

git diff

git diff shows the difference between a written cache and a modified but not yet written cache

Application scenario command
Changes not yet cached git diff
View cached changes git diff --cached
View all cached and uncached changes git diff HEAD
Show summary instead of the whole diff git diff --stat

git commit

git commit adds cache content to the repository
git commit -m "description"

git rm

git rm <file>	#Remove a file from Git
git rm --cached <file>	#Remove files from staging area (keep in current working directory)
git rm -f <file>	#Remove files from staging area (do not keep in current working directory)
git rm -r <dir>	   #Recursive deletion

git mv

git mv move or rename a t file, directory, soft connection

Submit to Github

git remote add anliu git@github.com:an1iu520/anliutest.git
git push -u anliu master

git client

git clone git@192.168.213.122:gitrepo/simple-java-maven-app

Posted by trixiesirisheyes on Tue, 16 Jun 2020 19:42:56 -0700