【Git】在GitHub或OSChina上新建项目后,如何在本地第一次push代码到服务器

时间:2023-03-08 16:20:09

场景1:将本地代码push到远程仓库上的master主分支

#初始化git,执行init命令后,默认新建本地分支master
git init

#关联远程仓库
git remote add origin https://git.oschina.net/mrx_my/blog.git

#git pull <远程主机名> <远程分支名>:<本地分支名>
#更新代码到本地
git pull origin master

git add .

git commit -m "初始化项目"

#git push origin master:master
#第一个master为本地分支,第二个分支为远程分支(不写则默认为当前分支);
#若本地分支为master,从远程服务器上的master更新到本地master分支,可以简写为:
git push origin master

场景2:若想push到其他分支

  • 本地分支为master,push到v1-tostar远程分支上去
...省去commit操作

git push origin master:v1-tostar
  • 看图

【Git】在GitHub或OSChina上新建项目后,如何在本地第一次push代码到服务器

【Git】在GitHub或OSChina上新建项目后,如何在本地第一次push代码到服务器

【Git】在GitHub或OSChina上新建项目后,如何在本地第一次push代码到服务器

【Git】在GitHub或OSChina上新建项目后,如何在本地第一次push代码到服务器

【Git】在GitHub或OSChina上新建项目后,如何在本地第一次push代码到服务器