如何用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 [email protected]:your_username/your_repository.git
方法2.先将已经添加过的,命名为origin的远程仓库给删了,然后重新添加
复制代码
git remote rm origin
git remote add origin [email protected]:your_username/your_repository.git
方法3:既然你已经将origin指向了某个远程仓库,那现在你换个名字指向另一个远程仓库就可以了
复制代码
git remote add origin2 [email protected]:your_username/your_repository.git

如果这样,那么push时就要

复制代码
git push origin2 master
相关推荐
露临霜4 小时前
vue实现AI问答Markdown打字机效果
前端·javascript·vue.js·ai·github
森叶5 小时前
Windows11 VS code 安装 Cline 调用 Github MCP 配置过程坑点汇总
github·ai编程
<<6 小时前
【0基础】Git使用教程
git
江鸟199813 小时前
AI 编程日报 · 2025 年 5 月 04 日|GitHub Copilot Agent 模式发布,Ultralytics 优化训练效率
人工智能·github·copilot
IoOozZzzz18 小时前
【Github仓库】Learn-Vim随笔
github·vim·excel
42fourtytoo1 天前
从0开始建立Github个人博客(hugo&PaperMod)
运维·服务器·python·go·github
山登绝顶我为峰 3(^v^)31 天前
Git 命令
大数据·git·算法·计算机
How_doyou_do1 天前
Git从入门到精通-第四章-更新仓库
git
qianmoQ2 天前
GitHub 趋势日报 (2025年05月01日)
github