如何用git将项目上传到github

步骤

1.创建仓库

2.记下仓库的url

3.在本地初始化仓库

路径要在项目下

复制代码
cd /path/to/your/vue-project
git init

4.创建touch .gitignore文件

在项目根目录下创建 .gitignore 文件,用于指定 Git 忽略哪些文件或文件夹

5.添加和提交项目文件

将文件提交到版本控制中

复制代码
git add .
git commit -m "Initial commit"

6.添加远程仓库并推送代码

将远程仓库添加到本地 Git 仓库,并推送代码到 GitHub。

复制代码
git remote add origin https://github.com/5z3c/test3.git
git push -u origin master

可能的问题

1.Git 无法识别你当前的身份信息(用户名和邮箱)的问题。Git 需要这些信息来记录谁提交了代码

复制代码
git config --global user.name "你的用户名"
git config --global user.email "你的邮箱"

2.fatal: remote origin already exists.

原因:你已经将一个远程仓库添加并命名为origin了,而现在你在尝试将另一个远程仓库添加并命名为origin

解决:
方法1.使用set-url修改origin仓库的url
复制代码
git remote set-url origin git@github.com:your_username/your_repository.git
方法2.先将已经添加过的,命名为origin的远程仓库给删了,然后重新添加
复制代码
git remote rm origin
git remote add origin git@github.com:your_username/your_repository.git
方法3:既然你已经将origin指向了某个远程仓库,那现在你换个名字指向另一个远程仓库就可以了
复制代码
git remote add origin2 git@github.com:your_username/your_repository.git

如果这样,那么push时就要

复制代码
git push origin2 master
相关推荐
miofly7 小时前
GitHub 今日推荐|DiPlay:让 iPhone CarPlay 直连 BYD 车机,无需硬件适配器
开源·github
行者-全栈开发7 小时前
【前端/JS框架】CVE-2026-3854:GitHub Enterprise Server X-Stat注入XSS漏洞深度剖析与紧急修复指南
前端·javascript·github
怕浪猫8 小时前
2026年9月面18个后端
后端·面试·github
掘金0112 小时前
Cursor Agent Prompt 拆解
人工智能·程序员·github
MinggeQingchun13 小时前
Git - 令牌登录
git
樱花落木兰13 小时前
SpringBoot + ECharts 后台数据统计报表模块实战
java·javascript·spring boot·ai·log4j·github·echarts
xhy_070715 小时前
Git 合并冲突怎么解决?用 AI 处理冲突的流程、Prompt 和 4 个易错点
人工智能·git·安全·prompt·ai编程·代码复审
Gu0Qiang16 小时前
从 0 到 1 打造 AI 提示流编排器:别把大模型当机械拼图!Case #7 字段冻结陷阱与代码回滚复盘(开源系列 15)
人工智能·github