![git将代码提交到远程分支(非主分支) git将代码提交到远程分支(非主分支)](https://image.shishitao.com:8440/aHR0cHM6Ly9ia3FzaW1nLmlrYWZhbi5jb20vdXBsb2FkL2NoYXRncHQtcy5wbmc%2FIQ%3D%3D.png?!?w=700&webp=1)
一个仓库可以包含多个分支,有一个默认的主分支:master
若想提交代码至远程仓库的某个分支(非主分支)
先查看下本地分支以及远程分支:git branch -a
![git将代码提交到远程分支(非主分支) git将代码提交到远程分支(非主分支)](https://image.shishitao.com:8440/.jpg?w=700&webp=1)
由本地分支(非主分支master)提交至远程分支,新建一个本地分支,并切换到此分支:
Git branch-b sunmaoyu origin/sunmaoyu
如果已有本地分支可直接切换:git checkout [name]
![git将代码提交到远程分支(非主分支) git将代码提交到远程分支(非主分支)](https://image.shishitao.com:8440/.jpg?w=700&webp=1)
\![git将代码提交到远程分支(非主分支) git将代码提交到远程分支(非主分支)](https://image.shishitao.com:8440/.jpg?w=700&webp=1)
![git将代码提交到远程分支(非主分支) git将代码提交到远程分支(非主分支)](https://image.shishitao.com:8440/.jpg?w=700&webp=1)
![git将代码提交到远程分支(非主分支) git将代码提交到远程分支(非主分支)](https://image.shishitao.com:8440/.jpg?w=700&webp=1aHR0cDovL2ltZy5ibG9nLmNzZG4ubmV0LzIwMTMwNzI1MTU1NzQ2NDA2P3dhdGVybWFyay8yL3RleHQvYUhSMGNEb3ZMMkpzYjJjdVkzTmtiaTV1WlhRdlUyMTVYM2wxL2ZvbnQvNWE2TDVMMlQvZm9udHNpemUvNDAwL2ZpbGwvSTBKQlFrRkNNQT09L2Rpc3NvbHZlLzcwL2dyYXZpdHkvU291dGhFYXN0)
接下来三步走:
git add .
git commit -a -m 'xxxxx'
git push origin sunmaoyu
![git将代码提交到远程分支(非主分支) git将代码提交到远程分支(非主分支)](https://image.shishitao.com:8440/.jpg?w=700&webp=1)
![git将代码提交到远程分支(非主分支) git将代码提交到远程分支(非主分支)](https://image.shishitao.com:8440/.jpg?w=700&webp=1)