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 新分支名
相关推荐
1379003408 小时前
Git 设置代理
git
xiaodunmeng15 小时前
sourcetree gitee 详细使用
git
LostSpeed16 小时前
git,gitea - tool - creat Gitea Empty Rep Dir
git·gitea
前端郭德纲18 小时前
vscode默认终端怎么设置成git bash
git·vscode·bash
近听水无声4771 天前
git 学习(基于Ubuntu和gitee)
git
2401_826097622 天前
同步&异步日志系统-日志落地模块的实现
c++·git·vim
半旧夜夏2 天前
阿里云IOT消息处理
java·ide·git·物联网·spring·阿里云
我们的五年2 天前
【Git版本控制器】第三弹——版本回退,撤销修改,删除文件
大数据·linux·git
一名嵌入式糕手2 天前
Git从基础到进阶
git
不cong明的亚子2 天前
github用户名密码登陆失效了
git·github