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 新分支名
相关推荐
jiayong235 小时前
Git 核心概念:Tag 与 Branch 的本质区别
git
Serene_Dream8 小时前
git 合并冲突的分支
git
我是一只puppy9 小时前
使用AI进行代码审查
javascript·人工智能·git·安全·源代码管理
玄同7659 小时前
Git常用命令指南
大数据·git·elasticsearch·gitee·github·团队开发·远程工作
十步杀一人_千里不留行13 小时前
Git提交前ESLint校验实践(Husky + lint-staged)
git·github
hh随便起个名15 小时前
适合小白的git的基础使用方法
git
我会一直在的16 小时前
Devps持续集成
git·ci/cd
CoderJia程序员甲17 小时前
GitHub 热榜项目 - 日榜(2026-02-08)
git·ai·开源·llm·github
Serene_Dream18 小时前
git 常用命令
git
jiayong2318 小时前
Detached HEAD 状态详解
git