如何在 vscode 上用 git 将项目 push 到远程仓库 and 常用Git 命令

一、将项目 push 到远程仓库步骤:

1.打开终端,运行以下命令初始化 Git 仓库

bash 复制代码
git init

2.添加远程仓库地址

bash 复制代码
git remote add origin <GitLab仓库地址>

如果缺少这步会报以下错误,直接来一遍该命令即可。

3.基于本地 main 创建 develop 分支

bash 复制代码
git checkout -b develop

4.确认当前分支

bash 复制代码
git branch

5.推送 develop 到远程仓库

bash 复制代码
git push -u origin develop

可以在git上看见多了个branch,并且里面多了一条develop的分支。

5.后续开发就在 develop 分支进行,接着就是推送三步走

bash 复制代码
git add .
git commit -m "提交说明:例如 '完成xxx功能开发"  // 后面引号部分自行修改,在远程仓库会显示,相当于备注
git push  # 已关联,直接推送

二、以下是一些常用的git命令:

删除冗余的远程仓库

bash 复制代码
git remote remove 项目名称

拉取远程 master 分支的最新代码到本地分支

bash 复制代码
git pull origin master --rebase // master可改为具体分支

创建并切换到 develop 分支

bash 复制代码
git checkout -b develop // develop可改为具体分支

查看本地所有分支

bash 复制代码
git branch

查看远程所有分支

bash 复制代码
git branch -r

-u 表示关联本地 master 和远程 origin/master

bash 复制代码
git push -u origin master  

查看当前远程仓库列表

bash 复制代码
git remote -v

删除所有无效的远程仓库(根据列表中的名称删除)

bash 复制代码
git remote remove 无效的远程名称  

添加一个规范的远程仓库名称(通常用 origin,方便后续操作)

bash 复制代码
git remote add origin 远程仓库网址
相关推荐
手揽回忆怎么睡18 分钟前
opencode和TRAE使用Superpowers 和ui-ux-pro-max skillls
ide·ui·ai·ux
CaracalTiger30 分钟前
OpenClaw-VSCode:在 VS Code 中通过 WebSocket 远程管理 OpenClaw 网关的完整方案
运维·ide·人工智能·vscode·websocket·开源·编辑器
CoderJia程序员甲1 小时前
GitHub 热榜项目 - 日榜(2026-02-08)
git·ai·开源·llm·github
CS创新实验室2 小时前
Pandas 3 的新功能
android·ide·pandas
-嘟囔着拯救世界-2 小时前
【2026 最新版】OpenAI 祭出王炸 GPT-5.3-Codex!Win11 + VSCode 部署保姆级教程
vscode·gpt·chatgpt·node.js·node·codex·gpt5
Serene_Dream2 小时前
git 常用命令
git
jiayong232 小时前
Detached HEAD 状态详解
git
李少兄12 小时前
在 IntelliJ IDEA 中修改 Git 远程仓库地址
java·git·intellij-idea
先跑起来再说18 小时前
Git 入门到实战:一篇搞懂安装、命令、远程仓库与 IDEA 集成
ide·git·后端·elasticsearch·golang·intellij-idea
嵌入小生00720 小时前
标准IO---核心函数接口延续(嵌入式Linux)
c语言·vscode·vim·嵌入式·小白·标准io·函数接口