惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Google DeepMind News
Google DeepMind News
N
Netflix TechBlog - Medium
The Register - Security
The Register - Security
C
Cybersecurity and Infrastructure Security Agency CISA
H
Hackread – Cybersecurity News, Data Breaches, AI and More
The Hacker News
The Hacker News
P
Proofpoint News Feed
Project Zero
Project Zero
The GitHub Blog
The GitHub Blog
The Last Watchdog
The Last Watchdog
F
Fortinet All Blogs
S
Schneier on Security
Help Net Security
Help Net Security
Security Archives - TechRepublic
Security Archives - TechRepublic
C
Check Point Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
P
Proofpoint News Feed
I
InfoQ
T
The Blog of Author Tim Ferriss
Cisco Talos Blog
Cisco Talos Blog
Stack Overflow Blog
Stack Overflow Blog
T
Troy Hunt's Blog
人人都是产品经理
人人都是产品经理
T
Threatpost
www.infosecurity-magazine.com
www.infosecurity-magazine.com
C
Cyber Attacks, Cyber Crime and Cyber Security
雷峰网
雷峰网
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
爱范儿
爱范儿
Forbes - Security
Forbes - Security
Vercel News
Vercel News
S
Security Affairs
美团技术团队
P
Privacy & Cybersecurity Law Blog
N
News and Events Feed by Topic
Cyberwarzone
Cyberwarzone
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Jina AI
Jina AI
Spread Privacy
Spread Privacy
Attack and Defense Labs
Attack and Defense Labs
IT之家
IT之家
U
Unit 42
Recorded Future
Recorded Future
W
WeLiveSecurity
PCI Perspectives
PCI Perspectives
P
Palo Alto Networks Blog
H
Hacker News: Front Page
S
Security @ Cisco Blogs
博客园 - 【当耐特】

LimeBit

我写了一个 Windows 灵动岛 - LimeBit 记录解决 git 拉取速度慢的解决办法 - LimeBit 当年全网疯找的100%晴女网站,我给它做了个完美复刻版! - LimeBit 回顾:微信小程序用户授权登录 - LimeBit VUE3:初入门槛 - LimeBit 海内存知己,天涯若比邻。欢迎光临我的博客! - LimeBit 内网穿透 | frp 自建内网穿透服务操作心得 - LimeBit Web与微信云开发交互:SDK小程序数据库操作 - LimeBit 实践记录:《企业多业务网络融合部署》—— IP路由通信 - LimeBit 1Panel - 食用方法以及心得 - LimeBit
Git:启程 - LimeBit
Ryen · 2025-11-13 · via LimeBit
头图

引言

最近在开发一款 Vue3 + Electron + Ts 的桌面端应用,但是在项目源代码管理这一块有点头疼,以往我的方式是选择在本地手动复制一份备份,但这无法从根本解决代码管理。

于是我昨天突然想到了之前刷到过的一个东西:Git

首先我先让自己理解 什么是 Git

Git 是一个 分布式版本控制系统 ,用于跟踪文件的变化,特别是代码文件的变更。它允许多人协同开发,记录每次修改的历史,支持分支管理,方便回滚和合并代码。Git 不依赖中央服务器,每个开发者本地都有完整的版本库,因此操作快速且灵活,是现代软件开发中最常用的版本控制工具之一。

Git&Github.png
Git&Github.png

如何快速让项目启动Git?

方法1:全新项目(从零开始)

# 1. 进入项目目录
cd your-project-folder

# 2. 初始化Git仓库
git init

# 3. 添加所有文件到Git
git add .

# 4. 创建第一次提交
git commit -m "初始提交"

# 5. 连接到远程仓库(可选)
git remote add origin https://github.com/username/repo.git

# 6. 推送到远程仓库(可选)
git push -u origin master

方法2:克隆现有项目

# 从GitHub等平台克隆已有项目
git clone https://github.com/username/repo.git

方法3:已有项目连接到远程仓库

# 1. 初始化Git
git init

# 2. 添加远程仓库
git remote add origin https://github.com/username/repo.git

# 3. 拉取远程内容(如果有)
git pull origin master

# 4. 添加并提交本地文件
git add .
git commit -m "添加本地文件"

# 5. 推送到远程
git push -u origin master

Git 开发日常流程

# 查看当前状态
git status

# 添加修改到暂存区
git add .

# 提交修改
git commit -m "描述修改内容"

# 推送到远程仓库
git push origin master

Tips: 日常开发建议 push 到 master 分支,在 master 分支上进行开发。当有需要时再把代码同步到 main 分支。

当有新的提交需要推送到 Github 时:

git push origin master
git push origin master:main --force

另外附上 Git 常用命令,方便复习和后续使用。

# 查看状态
git status

# 提交变更
git add .

# 整合到本地仓库
git commit -m "描述修改内容"

# 提交推送到 Github(最重要,频繁操作)
git push origin master

# 查看提交历史
git log --oneline --graph

# 检查本地和远程分支状态
git branch -a

# 查看差异
git diff

# 创建分支
git branch 分支名

# 切换分支
git checkout 分支名

# 将分支的更改合并到当前分支
git merge 分支名

# 拉取远程更改
git pull origin 分支名

# 查看远程仓库
git remote -v

# 暂存未跟踪文件
git stash -u

#查看Github默认分支设置
git ls-remote origin

开发时遇到的问题

昨日我在使用 Git 向 Github 的 main 分支首次尝试推送我的代码时,我遇到了问题:

我使用命令 git checkout main 以后,工作区和目录切换到了 main 分支,故之前所有的文件都不见了,我以为代码都丢了十分火急,后续才了解到原来这是 Git 的特性。

当进入 main 分支以后,使用命令 git merge master 把 master 分支的代码合并到此分支,再使用 git push origin main 进行推送。

但如果想保留当前工作区,即保留在 master 分支上,可以使用 git push origin master:maingit push origin master:main --force 向 main 分支合并代码。

完成后查看远程仓库状态:git ls-remote origin

总结完毕!

兴许我会在下一次写一篇 Github 使用心得。