Ubuntu从零开始配置Git

Ubuntu从零开始配置Git

你在 Ubuntu 上从零开始操作,包含 安装 Git、配置用户、生成 token、上传 Gazebo 项目 的全部步骤。

你可以直接复制到终端执行(记得把占位符替换成你的信息)。


🔹 一、安装 Git

bash 复制代码
sudo apt update
sudo apt install git -y
git --version  # 验证安装

🔹 二、配置 Git 用户信息

bash 复制代码
git config --global user.name "你的名字"
git config --global user.email "你的邮箱@example.com"

# 检查配置
git config --global --list

⚠️ 确保邮箱和用户名和你在 Gitee 上的一致。


🔹 三、进入你的 Gazebo 项目目录

bash 复制代码
cd ~/my_gazebo_project

🔹 四、初始化 Git 仓库并提交

bash 复制代码
git init

# 可选:创建 .gitignore 避免提交临时文件
echo "*.log
*.tmp
*.bak
*~
.DS_Store" > .gitignore

git add .
git commit -m "Initial commit: Gazebo world and models"

🔹 五、在 Gitee 创建 Personal Access Token

  1. 登录 Gitee → 点击头像 → 设置安全设置 → 个人访问令牌
  2. 点击 生成新令牌 ,勾选权限:
    • projects
    • repositories
    • user_info
  3. 保存生成的 token(只显示一次!)

🔹 六、配置远程仓库(使用 token)

假设你的 Gitee 用户名:alex-mercer

仓库名:intellegent-community-project

<TOKEN> 替换为你生成的 token:

bash 复制代码
git remote add origin https://alex-mercer1210:<TOKEN>@gitee.com/alex-mercer1210/intellegent-community-project.git

验证远程仓库:

bash 复制代码
git remote -v

🔹 七、推送到远程仓库

bash 复制代码
git branch -M main   # 确保本地分支为 main
git push -u origin main

如果推送成功,终端会显示:

复制代码
* [new branch]      main -> main
分支 'main' 设置为跟踪来自 'origin' 的远程分支 'main'

🔹 八、可选:让 Git 记住 token,避免每次输入

bash 复制代码
git config --global credential.helper store

下次 git push 时输入用户名和 token,Git 会自动保存。


🔹 九、日常更新操作

当你修改 Gazebo 项目后,只需:

bash 复制代码
git add .
git commit -m "更新描述"
git push

✅ 这样就完成了从零安装 Git,到在 Gitee 创建仓库,再到上传和管理你的项目的流程。

相关推荐
clint4561 天前
C++进阶(1)——前景提要
c++
夜悊2 天前
C++代码示例:进制数简单生成工具
c++
深海鱼在掘金2 天前
Git 完全指南 —— 第1章:Git 概览与版本控制演进
git
郝学胜_神的一滴2 天前
CMake 021: IF 条件判据详诠
c++·cmake
_wyt0012 天前
洛谷 B3930 [GESP202312 五级] 烹饪问题 题解
c++·gesp
玖玥拾2 天前
C/C++ 数据结构(七)栈、容器适配器
c语言·数据结构·c++··容器适配器
один but you2 天前
constexpr函数
c++
noravinsc2 天前
关于Git Flow
git
凡人叶枫2 天前
Effective C++ 条款41:了解隐式接口和编译期多态
java·开发语言·c++·effective c++
凡人叶枫2 天前
Effective C++ 条款42:了解 typename 的双重意义
java·linux·服务器·c++