git本地分支推送到远程分支

1、创建的创建和初始化

创建git仓库可以在远端创建一个仓库,
然后check到本地,在本地的文件里创建工程文件,然后提交

也可以将本地现有的工程和远端的空仓库关联
本地创建了一个工程 iOSDemo
运行没有错误,就可以提交到远端了。

一般情况下,远端仓库创建成功之后会有以下提示

#Command line instructions

#Git global setup
git config --global user.name "wangjiangwei336"
git config --global user.email "ex_wljr_wangjiangwei@pingan.com.cn"

#Create a new repository
git clone http://gitlab.pab.com.cn/CARF/DUN-CLDS/dun-clds-open-front/ios/CarLoanAppR11.git
cd CarLoanAppR11
touch README.md
git add README.md
git commit -m "add README"
git push -u origin master

#Existing folder
cd existing_folder
git init
git remote add origin http://gitlab.pab.com.cn/CARF/DUN-CLDS/dun-clds-open-front/ios/CarLoanAppR11.git
git add .
git commit -m "Initial commit"
git push -u origin master

#Existing Git repository
cd existing_repo
git remote rename origin old-origin
git remote add origin http://gitlab.pab.com.cn/CARF/DUN-CLDS/dun-clds-open-front/ios/CarLoanAppR11.git
git push -u origin --all
git push -u origin --tags

2、

git创建分支并切换到当前新创建的分支上
git checkout -b dev
开发完成后
git push origin dev

此时就将本地分支推送到远程相应的分支上了
记得推到远端之前先拉取最新代码
git pull

然后如果本地有一个分支是你创建的dev0628 ,是不能直接提交代码到远程的,因为远程并没有一个叫 origin/dev0628 的分支,需要将本地dev0628 关联到远程 origin/dev0628
$git branch --set-upstream dev0628 origin/dev0628
fatal: the '--set-upstream' option is no longer supported. Please use '--track' or '--set-upstream-to' instead.

--set-upstream已经过时,需要用 新的命令 --set-upstream-to
$git branch --set-upstream-to origin/dev0628
Branch 'dev0628' set up to track remote branch 'dev0628' from 'origin'.

这样本地分支就和远程分支关联起来了

[https://www.cnblogs.com/sugar-tomato/p/8295033.html]

原文地址:https://www.cnblogs.com/wjw-blog/p/11103288.html