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 新分支名
相关推荐
222you10 小时前
Git的diff命令
git
补三补四12 小时前
Git 基础操作指南
大数据·git·elasticsearch
222you20 小时前
git的命令
git
Coolbike21 小时前
Git工作流
git
~央千澈~1 天前
实战针对本地项目git如何移除旧仓库关联并且添加关联新仓库-优雅草卓伊凡
git
JH30731 天前
git常用命令大全
git
ll5776443322 天前
使用PyTorch实现自定义损失函数以FocalLoss为例的详细教程
git
李少兄2 天前
Git 用户名与邮箱配置指南
git
Blue啊2 天前
code Merge(qcc)
git·gitlab
洛小豆2 天前
Git打标签仓库看不到?她说:豆子,你又忘了加 --tags!
git·后端·github