码云和Github操作相同
步骤
1.在代码托管仓(码云、github)库新建一个项目
选择新建项目
![](https://img.haomeiwen.com/i11483779/e81782eab8ab0197.png)
填写项目配置
![](https://img.haomeiwen.com/i11483779/67ef9ad1c86b809c.png)
填写完后点创建,进入如下界面
![](https://img.haomeiwen.com/i11483779/a1d453d538cb0ccd.png)
2.在本地新建项目(也可以使用已存在的项目)
新建android studio项目,打开项目所在文件
![](https://img.haomeiwen.com/i11483779/8439ebb55723837c.png)
右键选择Git Bash here
![](https://img.haomeiwen.com/i11483779/8a7b59583566699c.png)
3.依次执行以下命令
git init
初始化本地仓库
![](https://img.haomeiwen.com/i11483779/511c4af871aa80ee.png)
git remote add origin 你的仓库地址
复制这个地址
![](https://img.haomeiwen.com/i11483779/956807a8a3517ac3.png)
关联本地仓库到远程仓库
![](https://img.haomeiwen.com/i11483779/028db31968ba895f.png)
git add .
添加要提交的文件到暂存区
![](https://img.haomeiwen.com/i11483779/38d81681351dd35d.png)
git commit -m "init"
提交代码到文件控制仓库
![](https://img.haomeiwen.com/i11483779/20fff14f8e950536.png)
git push origin master -f
提交本地分支(master)代码到远程分支(master)
![](https://img.haomeiwen.com/i11483779/0d0b74909604197d.png)
4.完成,上云端查看
![](https://img.haomeiwen.com/i11483779/aa51ed94c3f6cefd.png)
5.遇到的问题
使用git push origin master命令,可能会遇到以下这种问题
Pushing to git@github.com:519ebayproject/519ebayproject.git
To git@github.com:519ebayproject/519ebayproject.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'git@github.com:519ebayproject/519ebayproject.git'
hint: Updates were rejected because the tip of your current 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 reset命令,版本回退后没有恢复,造成本地仓库的提交版本号落后于远端仓库的提交版本号。
可以执行 git push -f命令去强制提交
网友评论