如果经常上传代码到github,会遇到这种情况,原本在本地创建的项目,怎么才能关联到远程仓库呢?本文将详细介绍使用步骤。
1、进入项目根目录,初始化本地仓库
git init
2、把项目文件添加到本地版本库
git add .
3、提交本地版本库,引号内为提交说明
git commit -m '版本说明'
4、关联到远程库
git remote add origin 远程库地址
如果上面步骤写错了,则删除之后再重新添加
git remote rm origin //删除origin
5、获取远程库与本地同步合并(如果远程库不为空必须做这一步,否则后面的提交会失败)
git pull --rebase origin master
6、将最新的修改推送到远程仓库:
git push -u origin master
备注:
origin:远程仓库名字
master:分支
注意:
第一次push的时候加上-u参数,Git就会把本地的master分支和远程的master分支进行关联起来,以后的push操作就不再需要加上-u
如果出现类似下面内容:
Username for 'https://github.com': shiren1118
Password for 'https://shiren1118@github.com':
To https://github.com/shiren1118/iOS_code_agile.git
![rejected] master -> master(non-fast-forward)
error: failed to push some refs to'https://github.com/shiren1118/iOS_code_agile.git'
hint: Updates were rejected because the tip of yourcurrent branch is behind
hint: its remote counterpart. Merge the remote changes(e.g. 'git pull')
hint: before pushing again.
hint: See the 'Note about fast-forwards' in 'git push--help' for details.
则输入命令:
git push -u origin master –f
如果从在git服务器所在主机上的其他账户获取git服务器上面文件,则直接用
git clone git仓库的路径
=================================================================
个人博客
Github
个人公众号:Flutter小同学
个人网站