如何将本地项目提交到 GitHub

目录

1、首先在 GitHub 上创建一个新的仓库:

java 复制代码
1. 登录 GitHub
2. 点击右上角 "+" 号
3. 选择 "New repository"
4. 填写仓库名称
5. 不要勾选 "Initialize this repository with a README"
6. 点击 "Create repository"

2、在本地项目中初始化 Git:

java 复制代码
# 进入项目目录
cd your-project-path

# 初始化 Git
git init

# 添加所有文件到暂存区
git add .

# 创建第一次提交
git commit -m "first commit"

3、添加远程仓库并推送:

java 复制代码
# 添加远程仓库(替换 USERNAME 和 REPO-NAME)
git remote add origin https://github.com/USERNAME/REPO-NAME.git

# 将本地 main 分支推送到远程
git branch -M main
git push -u origin main

4、如果你想忽略某些文件不提交,创建 .gitignore 文件:

java.DS_Store 复制代码
node_modules
/dist

# local env files
.env.local
.env.*.local

# Log files
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*

# Editor directories and files
.idea
.vscode
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?

5、如果遇到推送失败,可能需要:

java 复制代码
# 设置 Git 用户信息
git config --global user.name "Your Name"
git config --global user.email "your.email@example.com"

# 如果需要设置 token 认证(推荐)
# 1. 在 GitHub 设置中生成 Personal Access Token
# 2. 使用 token 替换密码进行认证

6、常用的 Git 命令:

java# 复制代码
git status

# 查看分支
git branch

# 创建并切换分支
git checkout -b feature-name

# 合并分支
git merge feature-name

# 拉取远程更新
git pull origin main

# 查看提交历史
git log

7、如果想将现有的远程仓库克隆到本地:

java 复制代码
git clone https://github.com/USERNAME/REPO-NAME.git
相关推荐
GoGeekBaird29 分钟前
GoHumanLoopHub开源上线,开启Agent人际协作新方式
人工智能·后端·github
草梅友仁11 小时前
草梅 Auth 1.4.0 发布与 ESLint v9 更新 | 2025 年第 33 周草梅周报
vue.js·github·nuxt.js
寻月隐君12 小时前
硬核实战:从零到一,用 Rust 和 Axum 构建高性能聊天服务后端
后端·rust·github
CoderJia程序员甲16 小时前
GitHub 热榜项目 - 日榜(2025-08-16)
人工智能·ai·开源·github
python_13619 小时前
web请求和响应
java·spring·github
一宿君1 天前
Github 9 个惊艳的开源 NL2SQL 项目
sql·nlp·github
x10n91 天前
GitHub宕机时的应急协作方案
github
深圳多奥智能一卡(码、脸)通系统2 天前
以下是对智能电梯控制系统功能及系统云端平台设计要点的详细分析,结合用户提供的梯控系统网络架构设计和系统软硬件组成,分点论述并补充关键要点:
github
掘金安东尼2 天前
使用自定义高亮API增强用户‘/’体验
前端·javascript·github
星哥说事2 天前
如何将堡塔云WAF迁移到新的服务器
服务器·git·github