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 新分支名
相关推荐
5***a97530 分钟前
Git虚拟现实案例
git·vr
牛奔1 小时前
git 清理未跟踪文件
git
摇滚侠4 小时前
VsCode 自带的 Git 使用教程
ide·git·vscode
H***99764 小时前
Git物联网案例
git·物联网
g***B7385 小时前
Git版本控制工具对比
git
weixin_456904276 小时前
Git大文件管理与版本回退
大数据·git·elasticsearch
J***Q2929 小时前
Git虚拟现实开发
git·vr
油丶酸萝卜别吃10 小时前
GitHub 上查找中国乡镇经纬度范围数据的开源项目
git·github
9***P33421 小时前
Git测试框架使用指南
git
X***48961 天前
Git数据分析应用
git