Git工程日常下拉/上传完整流程(自用)

Git 日常下拉 / 上传完整流程

适用于 GitLab / GitHub / 公司内部代码管理

常用命令速查

场景 命令
查看状态 git status
查看分支 git branch
切换分支 git checkout xxx
新建分支 git checkout -b xxx
拉远程 git pull
加入暂存 git add .
本地提交 git commit -m "msg"
推送远程 git push
查看提交 git log --oneline

一、首次使用(只需一次)

1. 克隆仓库

bash 复制代码
git clone <repo_url>
cd <repo_dir>

2. 配置用户信息

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

检查:

bash 复制代码
git config --global --list

二、日常标准流程(常用)

1.下拉远程最新代码(写代码前)

bash 复制代码
# 每次写代码前(防冲突), 防止在旧代码上开发,避免 push 冲突
git pull

2.查看 / 切换分支

bash 复制代码
git branch  # # 看当前分支
git checkout master
# 或新建功能分支(推荐)
git checkout -b feature/xxx

3.编码 & 修改文件

  • 写代码
  • 新增 / 修改 / 删除文件

4.查看修改状态

bash 复制代码
git status
#常见结果:
# - 红色:未加入暂存区   
# - 绿色:已加入暂存区

5.加入暂存区

bash 复制代码
git add .
# 或
git add <file> # 只加某个文件
例如:git add perception/multi_pc_fusion/pcf_server_wes_yolo.py

6.本地提交

bash 复制代码
git commit -m "提交说明"
# 此时仅在本地,未到远程仓库

7.推送到远程仓库

代码真正提交到 GitLab

bash 复制代码
git push
# 首次推送
git push -u origin <branch>  # 第一次

三、多人协作必备

push 被拒绝(常见 如"rejected (fetch first)"),解决如下,

bash 复制代码
git pull --rebase
git push

这样历史更干净,不容易乱

流程总结

整体流程:下拉工程 → 写代码 → add → commit → push

bash 复制代码
git pull
# 写代码
git add .
git commit -m "说明"
git push
相关推荐
leoZ23112 小时前
Git 集成实战完全指南(三):自动化 Commit 与 PR
大数据·git·elasticsearch
国服第二切图仔15 小时前
002-Claude Code 项目解读:入口与启动流程
linux·git·ubuntu
天空'之城16 小时前
VS Code Git 工作树:告别频繁切分支,实现多分支并行开发实战方案
git·vscode·版本控制·嵌入式开发·开发效率·worktree·多分支管理
程序员爱德华17 小时前
VSCode git/gerrit解冲突
git·vscode·gerrit
leoZ2311 天前
Git 集成实战完全指南(二):智能分支管理
大数据·git·elasticsearch
qq_452396231 天前
第六篇:《GitLab CI 进阶:多环境部署与环境变量管理》
git·ci/cd·gitlab
有想法的py工程师1 天前
GPG 密钥迁移指南:多私钥备份、批量导入与自动信任
git·github
浮江雾1 天前
Flutter第五节------Flutter开发环境配置与项目创建指南
开发语言·前端·git·学习·flutter·入门·函数
aramae2 天前
C++11:现代C++的里程碑
c语言·开发语言·c++·windows·git·后端
BerryS3N2 天前
VS Code Git 工作树:解锁多分支并行开发新体验
大数据·git·elasticsearch