以下是如何在 Git 中创建新分支,然后将其推送到 GitHub 的步骤。
例如,你的新分支名称为 development。
1. 检查当前分支
git branch
2. 创建新分支并立即切换
git checkout -b development
或者使用最新版本的 Git:
git switch -c development
3. 检查是否已切换到新分支
git branch
活跃分支通常用星号(*)标记,例如:
* development
main
4. 添加文件更改
git add .
5. 提交更改
git commit -m "Initial commit on development branch"
6. 将新分支推送到 GitHub
git push -u origin development
执行此命令后,development 分支将自动出现在你的 GitHub 仓库中。
💡 提示: 下次在同一分支上推送时,无需再输入完整命令。只需使用:
git push
完整流程示例:
git checkout -b development
git add .
git commit -m "Update project"
git push -u origin development
Tags:
#编程
W
作者
Wilan
巴厘岛Tekno的常驻撰稿人,积极分享技术、编程和软件工程领域的知识。
返回首页
最后更新日期:2026年6月15日