如何用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
相关推荐
宝桥南山30 分钟前
DeepSeek - 尝试一下GitHub Models中的DeepSeek
microsoft·ai·微软·c#·github·.net
不爱学英文的码字机器41 分钟前
[Git] 文件删除
git
lifeng43212 小时前
在 CentOS 上将 Ansible 项目推送到 GitHub 的完整指南
centos·github·ansible
DZSpace2 小时前
git stash命令用法
git
小华同学ai2 小时前
千万别错过!这个国产开源项目彻底改变了你的域名资产管理方式,收藏它相当于多一个安全专家!
前端·后端·github
Vowwwwwww2 小时前
GIT历史存在大文件的解决办法
前端·git·后端
@BreCaspian3 小时前
Git 推送失败解决教程——error: failed to push some refs to
大数据·git·elasticsearch
独立开阀者_FwtCoder6 小时前
一个 Cursor mdc 自动生成器,基于Gemini 2.5,很实用!
前端·javascript·github
我是哪吒6 小时前
分布式微服务系统架构第144集:FastAPI全栈开发教育系统
后端·面试·github
该换个名儿了6 小时前
git多个commit合并成一个
前端·git