Git切换分支并提交到远程分支

时间:2023-03-10 08:36:27
Git切换分支并提交到远程分支

1. 在本地需要提交的文件同级目录运行git bash

2. 初始化 git 运行环境

$ git init

3. 新建本地分支develop

$ git checkout -b decelop

4. 链接远程仓库

$ git remote add origin remote_address   

5. 同步远程仓库信息

$ git pull

 Git切换分支并提交到远程分支

6. 关联本地仓库与远程仓库

$ git branch --set-upstream-to=origin/develop develop

7. 若遇报错: branch 'develop' does not exist

Git切换分支并提交到远程分支

则运行如下指令:

$ git pull origin branch --allow-unrelated-histories
$ git branch --set-upstream-to=origin/develop develop

Git切换分支并提交到远程分支

8. 查看当前分支跟踪的远程分支

$ git branch -vv

Git切换分支并提交到远程分支

9. 同步远程分支

$ git pull

Git切换分支并提交到远程分支

10. 提交修改到远程分支

$ git add .
$ git commit -m "modify description"
$ git push

Git切换分支并提交到远程分支