码云和Github操作相同
步骤
1.在代码托管仓(码云、github)库新建一个项目
选择新建项目

填写项目配置

填写完后点创建,进入如下界面

2.在本地新建项目(也可以使用已存在的项目)
新建android studio项目,打开项目所在文件

右键选择Git Bash here

3.依次执行以下命令
git init
初始化本地仓库

git remote add origin 你的仓库地址
复制这个地址

关联本地仓库到远程仓库

git add .
添加要提交的文件到暂存区

git commit -m "init"
提交代码到文件控制仓库

git push origin master -f
提交本地分支(master)代码到远程分支(master)

4.完成,上云端查看

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命令去强制提交
网友评论