如何用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
相关推荐
passerby606131 分钟前
如何自己造一个时间处理库
前端·javascript·github
云泽8082 小时前
Git 版本控制系统(下):从 .git 目录结构到冲突解决机制详解
大数据·git·elasticsearch
小弥儿5 小时前
GitHub今日热榜 | 2026-09-04:Agent省 token 成今日主线
学习·开源·github
苏灿烤鱼8 小时前
给 AI Agent 装一个「会进化的大脑」:OpenViking 深度拆解
开源·github·agent
逛逛GitHub8 小时前
清华开源的 Agent 交互学习神器,又登上 GitHub 热榜了。
github
麻辣布丁8 小时前
Git冲突原因与解决方法全解
大数据·git·elasticsearch
其实防守也摸鱼9 小时前
OpenClaw Windows 踩坑实战指南
运维·服务器·数据库·windows·github·copilot
小马92611 小时前
从单模型到多模型编排:GitHub HydraFusion 如何让编程 Agent 降本 36%-67%
人工智能·github
小弥儿11 小时前
GitHub今日热榜 | 2026-09-08:微软 markitdown 冲进前三
学习·microsoft·开源·github
蜡台12 小时前
超详细 GitHub Actions 自动发布部署教程
github·github page·github action