Git is a version control tool for Linux kernel development. Different from centralized version control tools such as CVS and Subversion, it adopts the practice of distributed version library, which does not need server-side software to operate version control, making the source code release and communication extremely convenient. Git is fast, which is naturally important for large projects such as the Linux kernel. Git is best known for its ability to merge tracing.
The wiki about the interpretation of the git, link: https://zh.wikipedia.org/wiki/Git
Git repositories can be built locally, or you can build a Git server. This article describes how to build a Git repository on a Linux server. Let’s Start!
Git server
- Create a Git user (dedicated Git user for Git connection, limited to code, etc.)
$ adduser git
Copy the code
opt
Create a folder under directorycode
$ mkdir /opt/code
Copy the code
- Once inside the folder, create a Git empty bin
$ cd code
$ git init --bare test.git
Copy the code
- View the git repository directory structure
$ cd test.git
Copy the code
- HEAD: indicates the branch currently checked out
- Config: contains project-specific configuration options
- Description: For GitWeb applications only
- Hooks: contains client-side or server-side hook scripts
- Info: Includes a global exclude file to place ignored patterns that do not want to be recorded in the.gitignore file.
- Objects: Stores all data contents
- Refs: Stores Pointers to commit objects that point to data (branches)
Automatic deployment function
Go to hooks to create a function (the hook that is automatically called when a pass is received) that allows the server to run code updates synchronously when the code is updated (this step is only for reference in automated deployment scenarios, the actual runtime environment should be used later as required).
$ cd hooks
$ vim post-receive
Copy the code
The content is to rewrite the specified workspace file, the code is as follows
#! /bin/bash
git --work-tree=/www/wwwroot/test checkout -f
Copy the code
In practice, ‘/ WWW /wwwroot/test’ should be replaced with the target project location. The git user must have permission for this directory
chown -R git:root /www/wwwroot/test
Copy the code
Finally, grant execute permission to the post-receive file
chmod +x post-receive
Copy the code
Create specific hook or not should be the implementation of different adjustment according to the project, with some companies manage code management is to use a dedicated server, the web control release branch merge, a key deployment, etc, this management published abstract layer, so that the release of the code, I don’t know everyone is how to realize version iteration, branch management? (Try implementing your own automated deployment if you still move the code manually.)
Git client
- Repository (replace IP with warehouse IP address)cloningGo to a new directory (available with a Git BASH client) or directly on the server, type
git clone /opt/code/test.git
$ git clone git@IP:/opt/code/test.git
Copy the code
- Go to the newly created directory and create the test file as follows
$ cd test
$ touch index.html
Copy the code
- Upload to the repository with the following code
$ git add .
$ git commit -m 'create index.html'
$ git push
Copy the code
- Enter the previously specified workspace folder to see if the code was submitted successfully, or clone a new code by repeating step 1, if the test file exists.
If an error occurs, you can run the chmod command to grant permission to the git user
Afterword.
Today, code management has developed many tools (such as SVN, CVS), code hosting platforms (such as Github, Gitlab) to choose from. In other words, code is like cargo, suitable version management is like a highly automated ship, with only a few crew members to steer the ship steadily to new routes, improve efficiency and welcome the new century.
\(•ㅂ•)/♥ ~