git 基本使用

git 基本使用

初始化本地项目并上传

  1. 创建远程仓库
  2. 创建本地项目
  3. 初始化本地项目git仓库
bash 复制代码
git init
  1. 关联远程仓库
bash 复制代码
git remote add origin 远程URL
  1. 将变更添加到git管理
bash 复制代码
git add .
  1. 提交到本地仓库
bash 复制代码
git commit -m "备注" 
  1. 提交到远程仓库-u:记录push分支,下次可简写git push 、 -f 强制推送
bash 复制代码
git push -u origin 远程分支

期间可能遇到的问题

  1. push报错,提示分支版本不一致等问题,可执行以下命令后再尝试push
bash 复制代码
git pull origin main --allow-unrelated-histories

git branch --set-upstream-to=origin/远程分支 本地要关联的分支

其他常用命令

  • 查看当前仓库仓库地址
bash 复制代码
git remote -v
  • 查看当前仓库本地和远程分支
bash 复制代码
git branch -a
  • 切换分支
bash 复制代码
git checkout 分支名
  • 从当前分支拉出一个新分支
bash 复制代码
git checkout -b 新分支名
相关推荐
雮尘16 小时前
让 AI Agent 高效并行开发的命令-git worktree
人工智能·git·agent
南果梨2 天前
OpenClaw 完整教程!从安装到使用(官方脚本版)
前端·git·开源
Selicens3 天前
git批量删除本地多余分支
前端·git·后端
闲云一鹤4 天前
Git LFS 扫盲教程 - 你不会还在用 Git 管理大文件吧?
前端·git·前端工程化
vibecoding日记6 天前
为什么我就想要「线性历史 + Signed Commits」,GitHub 却把我当猴耍 🤬🎙️
git·编程工具
程序员小崔日记7 天前
如何将代码轻松上传到 Gitee?Git 使用全攻略!
git·gitee·上传
Bigger8 天前
为什么你的 Git 提交需要签名?—— Git Commit Signing 完全指南
git·开源·github
DianSan_ERP8 天前
电商API接口全链路监控:构建坚不可摧的线上运维防线
大数据·运维·网络·人工智能·git·servlet
红豆子不相思9 天前
Tomcat 环境搭建与集群实战
服务器·git·tomcat