Ubuntu从零开始配置Git
Ubuntu从零开始配置Git
你在 Ubuntu 上从零开始操作,包含 安装 Git、配置用户、生成 token、上传 Gazebo 项目 的全部步骤。
你可以直接复制到终端执行(记得把占位符替换成你的信息)。
🔹 一、安装 Git
sudo apt update
sudo apt install git -y
git --version # 验证安装
🔹 二、配置 Git 用户信息
git config --global user.name "你的名字"
git config --global user.email "你的邮箱@example.com"# 检查配置
git config --global --list
⚠️ 确保邮箱和用户名和你在 Gitee 上的一致。
🔹 三、进入你的 Gazebo 项目目录
cd ~/my_gazebo_project
🔹 四、初始化 Git 仓库并提交
git init# 可选:创建 .gitignore 避免提交临时文件
echo "*.log
*.tmp
*.bak
*~
.DS_Store" > .gitignoregit add .
git commit -m "Initial commit: Gazebo world and models"
🔹 五、在 Gitee 创建 Personal Access Token
- 登录 Gitee → 点击头像 → 设置 → 安全设置 → 个人访问令牌
- 点击 生成新令牌,勾选权限:
projects
repositories
user_info
- 保存生成的 token(只显示一次!)
🔹 六、配置远程仓库(使用 token)
假设你的 Gitee 用户名:alex-mercer
仓库名:intellegent-community-project
将 <TOKEN>
替换为你生成的 token:
git remote add origin https://alex-mercer1210:<TOKEN>@gitee.com/alex-mercer1210/intellegent-community-project.git
验证远程仓库:
git remote -v
🔹 七、推送到远程仓库
git branch -M main # 确保本地分支为 main
git push -u origin main
如果推送成功,终端会显示:
* [new branch] main -> main
分支 'main' 设置为跟踪来自 'origin' 的远程分支 'main'
🔹 八、可选:让 Git 记住 token,避免每次输入
git config --global credential.helper store
下次 git push
时输入用户名和 token,Git 会自动保存。
🔹 九、日常更新操作
当你修改 Gazebo 项目后,只需:
git add .
git commit -m "更新描述"
git push
✅ 这样就完成了从零安装 Git,到在 Gitee 创建仓库,再到上传和管理你的项目的流程。