Command scope: SSH-key and clipboard examples use macOS / Unix-like terminals with OpenSSH;
pbcopyis macOS-specific. Server accounts use Linux examples. Check existing keys before generating a new one to avoid overwriting it.
ssh key configuration
1. Generate SSH Key
1. Check whether the .ssh folder exists
$ ls -al ~/.ssh2: Create the .ssh directory if needed and restrict its permissions:
$ mkdir -p ~/.ssh
$ chmod 700 ~/.ssh3: Generate a key with an OpenSSH version supporting Ed25519; replace the example email:
$ cd ~/.ssh
$ ssh-keygen -t ed25519 -C "your_email@example.com"Choose a save path and passphrase when prompted. The default filenames are id_ed25519 and id_ed25519.pub. Upload the public key and keep the private key locally.
4. View the public key
$ cat id_ed25519.pub5: Copy the public key to the clipboard (macOS):
$ pbcopy <id_ed25519.pubgit server prohibits user shell login
(1) Reasons for prohibition
In order to develop team projects, we often use distributed version management systems, of which git is the most important and commonly used distributed management system today. GitHub Free supports both public and private repositories, with some private-repository collaboration features depending on the plan. Choose self-hosting based on deployment, access control, and maintenance needs rather than an assumed inability to create free private repositories. After establishing the git server, everyone can pass
$ git clone git@10.3.0.99:project.gitClone the code locally. This also shows that everyone can also pass
$ ssh git@10.3.0.99SSH connects to the server, logs in to the server, and performs various operations on the server. This is usually unsafe and inappropriate. Members only need to be able to operate the warehouse and do not need greater permissions.
(2) Prohibition method
Editing the /etc/passwd file is completed.Find a line similar to the following:
git:x:1001:1001:,,,:/home/git:/bin/bash
改为:
git:x:1001:1001:,,,:/home/git:/usr/bin/git-shellThis restricts interactive shells while permitting Git SSH commands; verify executable paths, account policy and git-shell-commands settings on the server.
Git pushes a project to multiple remote repositories simultaneously
- Solution
Check the status of the remote warehouse,
git remote -vThe output is as follows. You can see that there is only one remote warehouse called origin.
origin git@github.com:xxx/xxx-ai.git (fetch)
origin git@github.com:xxx/xxx-ai.git (push)Use the following command to add a remote repository.(Create an empty library in advance)
git remote set-url --add origin git@192.168.31.111:xxx/xxx-ai.gitCheck the status of remote warehouse,
git remote -vYou can see that the origin remote warehouse has two push addresses.
origin git@github.com:xxx/xxx-ai.git (fetch)
origin git@github.com:xxx/xxx-ai.git (push)
origin git@192.168.31.111:xxx/xxx-ai.git (push)Front-end code git specification
(uftp_eff_20250301)[Ma Mingjuan]fix(Performance Center|20250301): Standard implementation field adjustment
special attention
Note
Configure user information uniformly in the project
git config user.name 马明娟 # Set the repository-local user nameThe following sentence must be executed separately for each project, otherwise the project information will be empty when submitting the code.
git config user.project uftp_eff_20250301 # 配置所属项目
git config user.projectCn 效能中心 # 配置项目中文名Method one
Configure content through git commands
git config --global user.name 马明娟 # 配置全局用户名
git config user.project uftp_eff_202503 # 配置所属项目
git config user.projectCn 效能中心 # 配置项目中文名
git config --global alias.fix '!f() { git commit -m "($(git config user.project))[$(git config user.name)]fix($(git config user.projectCn)|$(date +%Y%m%d)):$1"; }; f' # 修复bug
git config --global alias.feat '!f() { git commit -m "($(git config user.project))[$(git config user.name)]fix($(git config user.projectCn)|$(date +%Y%m%d)):$1"; }; f' # 新功能
git config --global alias.docs '!f() { git commit -m "($(git config user.project))[$(git config user.name)]fix($(git config user.projectCn)|$(date +%Y%m%d)):$1"; }; f' # 文档
git config --global alias.style '!f() { git commit -m "($(git config user.project))[$(git config user.name)]fix($(git config user.projectCn)|$(date +%Y%m%d)):$1"; }; f' # 格式,不影响代码运行的变动
git config --global alias.refactor '!f() { git commit -m "($(git config user.project))[$(git config user.name)]fix($(git config user.projectCn)|$(date +%Y%m%d)):$1"; }; f' # 重构,既不是新功能,也不是修改bug
git config --global alias.chore '!f() { git commit -m "($(git config user.project))[$(git config user.name)]fix($(git config user.projectCn)|$(date +%Y%m%d)):$1"; }; f' # 构建过程或辅助工具的变动
git config --global alias.revert '!f() { git commit -m "($(git config user.project))[$(git config user.name)]fix($(git config user.projectCn)|$(date +%Y%m%d)):$1"; }; f' # 撤销,版本回退
git config --global alias.pref '!f() { git commit -m "($(git config user.project))[$(git config user.name)]fix($(git config user.projectCn)|$(date +%Y%m%d)):$1"; }; f' # 性能优化
git config --global alias.test '!f() { git commit -m "($(git config user.project))[$(git config user.name)]fix($(git config user.projectCn)|$(date +%Y%m%d)):$1"; }; f' # 测试
git config --global alias.improvement '!f() { git commit -m "($(git config user.project))[$(git config user.name)]fix($(git config user.projectCn)|$(date +%Y%m%d)):$1"; }; f' # 改进
git config --global alias.build '!f() { git commit -m "($(git config user.project))[$(git config user.name)]fix($(git config user.projectCn)|$(date +%Y%m%d)):$1"; }; f' # 打包
git config --global alias.ci '!f() { git commit -m "($(git config user.project))[$(git config user.name)]fix($(git config user.projectCn)|$(date +%Y%m%d)):$1"; }; f' # 持续集成
git config --global alias.update '!f() { git commit -m "($(git config user.project))[$(git config user.name)]fix($(git config user.projectCn)|$(date +%Y%m%d)):$1"; }; f' # 更新Method two
Configuration via shell script
#!/bin/bash
# 定义用户信息
USER_NAME=$(git config user.name)
USER_PROJECT=$(git config user.project)
USER_PROJECTCN=$(git config user.projectCn)
# 定义数组
aliases = ("fix", "feat", "docs", "Style", "refactor", "chore", "revert", "pref", "test", "improvement", "build", "ci", "update")
# 循环遍历数组并配置别名
for alias in "${aliases[@]}"; do
git config --global alias."$alias" '!f() { git commit -m "($(USER_PROJECT))[$(USER_NAME)]$(alias)($(USER_PROJECTCN)|$(date +%Y%m%d));$1"; }; f'
done
echo "Git aliases with user information have been set."run script
- Save the script as setup_git_aliases_with_user.sh
- Make sure you have configured Git user information (git config user.name and git config user.project and git config user.projectCn)
- Add execution permissions to the script
chmod +x setup_git_aliases_with_user.sh- run script
./setup_git_aliases_with_user.shMethod three
Manually update user information
Here is the configuration based on the branch name
git config --global --editContents in the configuration file
[alias]
fix="!f(){ branch=$(git rev-parse --abbrev-ref HEAD); git commit -m \"($branch)[马明娟]fix(效能中心|$(date +%Y%m%d)); $1\"; }; f" # 修复bug
feat="!f(){ branch=$(git rev-parse --abbrev-ref HEAD); git commit -m \"($branch)[马明娟]feat(效能中心|$(date +%Y%m%d)); $1\"; }; f" # 新功能
docs="!f(){ branch=$(git rev-parse --abbrev-ref HEAD); git commit -m \"($branch)[马明娟]docs(效能中心|$(date +%Y%m%d)); $1\"; }; f" # 文档
style="!f(){ branch=$(git rev-parse --abbrev-ref HEAD); git commit -m \"($branch)[马明娟]style(效能中心|$(date +%Y%m%d)); $1\"; }; f" # 格式,不影响代码运行的变动
refactor="!f(){ branch=$(git rev-parse --abbrev-ref HEAD); git commit -m \"($branch)[马明娟]refactor(效能中心|$(date +%Y%m%d)); $1\"; }; f" # 重构,既不是新功能,也不是修改的bug
chore="!f(){ branch=$(git rev-parse --abbrev-ref HEAD); git commit -m \"($branch)[马明娟]chore(效能中心|$(date +%Y%m%d)); $1\"; }; f" # 构建过程或辅助工具的变动
revert="!f(){ branch=$(git rev-parse --abbrev-ref HEAD); git commit -m \"($branch)[马明娟]revert(效能中心|$(date +%Y%m%d)); $1\"; }; f" # 撤销,版本回退
pref="!f(){ branch=$(git rev-parse --abbrev-ref HEAD); git commit -m \"($branch)[马明娟]pref(效能中心|$(date +%Y%m%d)); $1\"; }; f" # 性能优化
test="!f(){ branch=$(git rev-parse --abbrev-ref HEAD); git commit -m \"($branch)[马明娟]test(效能中心|$(date +%Y%m%d)); $1\"; }; f" # 测试
improvement="!f(){ branch=$(git rev-parse --abbrev-ref HEAD); git commit -m \"($branch)[马明娟]improvement(效能中心|$(date +%Y%m%d)); $1\"; }; f" # 改进
build="!f(){ branch=$(git rev-parse --abbrev-ref HEAD); git commit -m \"($branch)[马明娟]build(效能中心|$(date +%Y%m%d)); $1\"; }; f" # 打包
ci="!f(){ branch=$(git rev-parse --abbrev-ref HEAD); git commit -m \"($branch)[马明娟]ci(效能中心|$(date +%Y%m%d)); $1\"; }; f" # 持续集成
update="!f(){ branch=$(git rev-parse --abbrev-ref HEAD); git commit -m \"($branch)[马明娟]update(效能中心|$(date +%Y%m%d)); $1\"; }; f" # 更新