使用git bash本地创建分支并将分支提交到远程仓库
第一次推送分支到远程仓库
打开 Git Bash。通过以下命令进入你的本地项目目录:
cd /path/to/your/project
git remote add origin <远程仓库URL>
例子:
git remote add origin https://github.com/username/repository.git
如果url不对可以通过一下命令修改url
git remote set-url origin <正确的远程仓库URL>
查看远程仓库
git remote -v
会出现以下内容
origin https://github.com/username/repository.git (fetch)
origin https://github.com/username/repository.git (push)
否则在push的时候会报错“Please tell me who you are.”
git config --global user.email "you@example.com"
git config --global user.name "Your Name"
运行以下命令,查看当前配置的用户名和邮箱:
git config --list
输出内容中应该包含以下两行:
user.name=你的名字
user.email=你的邮箱
使用以下命令在本地创建新分支(如 feature-branch)
git checkout -b feature-branch
输出结果类似于:
Switched to a new branch 'feature-branch'
git push origin feature-branch
推送成功后,输出结果类似于:
Enumerating objects: 3, done.
Counting objects: 100% (3/3), done.
Writing objects: 100% (3/3), 225 bytes | 225.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
To https://github.com/username/repository.git
* [new branch] feature-branch -> feature-branch
Branch 'feature-branch' set up to track remote branch 'feature-branch' from 'origin'.
提交本地更改并推送到远程分支
git status
git add .
git commit -m "添加了新功能"
git push