如何用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
相关推荐
fthux6 小时前
总想着“忙完再休息”?让 Tick Rest 提醒你,先歇一会儿
开源·github·mac·swift·提醒·消息提醒·tick rest·tick rest for mac·消息提醒app
dong_junshuai6 小时前
每天一个开源项目#156 Astryx:主题编译、异步按钮与源码接管
github
逛逛GitHub9 小时前
把你的 AirPods 当鼠标用,这 3 个黑科技 GitHub 开源项目有趣。
github
kuroomi11 小时前
Git入门
git·kubernetes
daliucheng11 小时前
lazygit 上手:日常 git 操作一篇讲完
git
徐小夕12 小时前
开源Vector-Graph-RAG:向量+图谱双引擎,打破纯向量RAG的效果天花板
前端·vue.js·github
GitHub实测笔记12 小时前
zoxide 本机实测:一万条记查询中 5.7ms0.10 版 import --from
github
codigger13 小时前
大厂git提交规范
git·程序员
挖掘狂人13 小时前
六条分支,一条主干:我的 Git 分支管理心得
git·后端·程序员
Brookty14 小时前
Git与GitHub系统学习|本地Git工作模型:终端与进程、CWD、HEAD/Index/工作树及Git对象
git·github