# 对于基于Debian的系统(Ubuntu等)
sudo apt-get update
sudo apt-get install git
# 对于基于RHEL的系统(CentOS, Fedora等)
sudo yum install git
git config --global user.name "Your Name"
git config --global user.email "your.email@example.com"
ssh-keygen -t ed25519 -C "your_email@example.com"
# 或者使用RSA
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519
cat ~/.ssh/id_ed25519.pub
# 复制输出内容并添加到Git服务器的SSH密钥设置中
git clone git@github.com:username/repository.git
cd repository
git remote add upstream git@github.com:original/repository.git
git config --global push.default current
# 创建新分支
git checkout -b feature-branch
# 开发完成后提交更改
git add .
git commit -m "描述你的更改"
# 推送到远程
git push -u origin feature-branch
git fetch upstream
git merge upstream/main
# 或者使用rebase
git rebase upstream/main
# 示例: 在.git/hooks/pre-commit中添加检查脚本
#!/bin/sh
npm run lint
# 创建.gitignore文件
touch .gitignore
# 添加需要忽略的文件/目录
echo "node_modules/" >> .gitignore
echo "*.log" >> .gitignore
# 安装Git LFS
sudo apt-get install git-lfs # Debian/Ubuntu
sudo yum install git-lfs # RHEL/CentOS
# 在仓库中启用
git lfs install
git lfs track "*.psd"
git add .gitattributes
# 查看远程仓库
git remote -v
# 获取远程更新但不合并
git fetch
# 查看分支差异
git diff branch1..branch2
# 交互式rebase
git rebase -i HEAD~3
# 创建标签
git tag -a v1.0 -m "版本1.0发布"
git push origin v1.0
<<<<<<<
, =======
, >>>>>>>
的冲突git add resolved-file
git commit
# 撤销上一次提交但保留更改
git reset --soft HEAD~1
# 完全撤销上一次提交
git reset --hard HEAD~1
# 查找删除的提交
git reflog
# 恢复分支
git checkout -b restored-branch <commit-hash>
通过以上配置和流程,您的团队可以在Linux系统上高效地进行Git协作开发。根据团队规模和项目复杂度,可以选择适合的工作流(如Git Flow, GitHub Flow等)来进一步优化协作流程。