Article Directory
1. Introduction to Git
Version control system, a system used to record changes in the content of one or more files, and to facilitate access to specific version revisions
Git:
- Distributed version control system, divided into local warehouse and remote warehouse
- Local warehouse: Git warehouse on the developer's own computer
- Remote warehouse: is a Git warehouse on a remote server
SVN:
- Centralized version control system, the version library is centralized on the central server
- Disadvantages: service single point of failure, poor fault tolerance
Two, Git workflow
1. Clone the code from a remote warehouse to a local warehouse
2. Checkout code from the local warehouse to the workspace
3. After modifying the code, add the modified content to the suspension area
4. Submit the content of the suspension area to the local warehouse, and the local warehouse will save all historical versions
5. Push the code from the local warehouse to the remote warehouse
Three, Git environment construction
1. Commonly used remote warehouses
- GitHub-foreign server, slow
- GitLab-the first choice for building yourself
- Jack Ma Gitee——Domestic server
2. Native Git operating environment
GitLab
setup① Create a new gitlab folder under /srv, and create cofig, logs, and data folders under the folder
mkdir /srv/gitlab
cd /srv/gitlab
mkdir config logs data
② Create and run the container, and mount the folder
docker run -di -p 端口:80 --hostname 宿主机ip --name mygitlab --restart always
-v /srv/gitlab/config:/etc/gitlab -v/srv/gitlab/logs:/var/log/gitlab
-v /srv/gitlab/data:/var/opt/gitlab -v /etc/localtime:/etc/localtime:ro --privileged=true gitlab/gitlab-ce
③ Host ip: port access gitlab
after entering the page, you will be asked to set a password (number + password), log in after the setting is complete
Login account: root, login password: password set by yourself
④ After the login is complete, the handling method on page 502
enter the gitlab container and enter the following command:
docker exec container id gitlab-ctl reconfigure #start the service in the container
systemctl stop firewalld #turn off the firewall
⑤ After the processing is completed, create a project
Git build
official website download address: http://git-scm.com/downloads
1. Create a new folder as a local warehouse
2. Right click git bash here
3. Configure the user name and email address to record the modification person
git config --global user.name "user name"
git config --global user.email "mailbox"
4. Enter the newly created local folder, right click git bash here
After git init is
executed, a .git file is generated, including temporary storage area and local warehouse
5. Clone the remote warehouse (no need to operate, it will be cloned in pycharm)
git clone remote warehouse url
Note: If the port is not 80, you need to add the port
6. Push the code to the remote warehouse (no need to operate, it will be operated in pycharm)
git add filename #Add the specified file to the temporary storage area
or git add. #Add all files to the temporary storage area
git commit -m "comment" #Submit to the local warehouse
git push origin branch name #Push the file to the server
Three, pycharm associated with gitlab
1. Set the installation path of git.exe
2. Clone the remote warehouse
3. Submit and push to the
push window of the remote warehouse to display the content to be pushed:
Four, gitlab and Jenkins are related to each other
1. Set up the Gitlab network, turn on allowing web hook information to be sent through the network
2. Set the gitlab information in jenkins
3. Set the jenkins information in Gitlab
① Enter the project configuration in Jenkins, and check the option in the build trigger (as shown in the figure) , The step is
③Note: If you don’t have this option, you need to install the gitlab and gitlab hook plug-ins
② In the above figure, click Advanced, find the Secret token to generate the token, and the steps used are ③
③ Fill in the contents of the first two steps below to
fill in When finished, swipe down to perform the following operations:
At this point, the configuration is complete.