1、本地创建git仓库,命令:git init
2、本地仓库和远程仓库关联,假设远程仓库在github上,地址为:https://github.com/xxx/xxx,执行命令:
git remote add origin https://github.com/xxx/xxx
3、本地项目push到远程,执行命令:git push origin xxx,具体参考如下情况:
推送本地分支local_branch到远程分支 remote_branch并建立关联关系,分为如下3种情况:
(1)远程已有remote_branch分支且已经关联本地分支local_branch且本地已经切换到local_branch,执行命令:
git push
(2)远程已有remote_branch分支但未关联本地分支local_branch且本地已经切换到local_branch,执行命令:
git push -u origin/remote_branch
(3)远程没有有remote_branch分支并,本地已经切换到local_branch,执行命令:
git push origin local_branch:remote_branch
4、若本地push到远程报错,需要看是否远程有更新未pull到本地,执行git命令:
git pull origin 远程分支名(如:master)
5、若在项目新建阶段,pull 报错,可以执行命令:
git pull origin master --allow-unrelated-history