-
首先在GitHub创建一个项目文件
-
进入本地创建项目所在文件夹
Git init
创建本地Git 环境 -
Git add .
将项目加载到暂存区。 -
Git commit -m "备注描述内容"
将项目加载到本地仓库区 -
git remote add origin https://gitee.com/MarchWood680/Block.git
关联本地库 同 远端库 -
git push -u origin master
(-u表示刚开始远程仓库没有内容,有了内容之后就不用再写了)
如果新建远程仓库不是空的,例如你勾选了 Initialize this repository with a README。那么你通过命令 $ git push -u origin master是会报错的,如下:
MarchWooddeMacBook-Pro:BlockTest marchwood$ git push -u origin master
To https://gitee.com/MarchWood680/Block.git
! [rejected] master -> master (fetch first)
error: failed to push some refs to 'https://gitee.com/MarchWood680/Block.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
MarchWooddeMacBook-Pro:BlockTest marchwood$
这是由于你新创建的那个仓库里面的README文件不在本地仓库目录中,这时我们可以通过以下命令先将内容合并以下:
git pull --rebase origin master
-
git push origin master
提交本地项目到远端库
网友评论