进入到你项目存放的根目录下。
敲入git init
初始化根目录下的项目。
敲入git add .
添加根目录下所有的项目。
敲入 git commit -m "commit"
提交所有项目,"commit"可以是任意字符串。
敲入 git remote add origin (粘贴你前面复制的HTTPS值)
,一般来说在
remote前先敲入git remote rm origin删除已有的HTTPS值
,避免找不到库。
最后把项目push上仓库 git push -f origin master 或者 git push -u origin master
可以直接 git push -f https://github.com/XXX/practiceLayui.git
但是push的时候可能会遇见一种情况
这是因为 两个 根本不相干的 git 库, 一个是本地库, 一个是远端库, 然后本地要去推送到远端, 远端觉得这个本地库跟自己不相干, 所以告知无法合并
具体的方法,
-
一个种方法: 是 从远端库拉下来代码 , 本地要加入的代码放到远端库下载到本地的库, 然后提交上去 , 因为这样的话,
你基于的库就是远端的库, 这是一次update了 -
第二种方法: 使用这个强制的方法
bash git pull origin master --allow-unrelated-histories
demo
git pull https://github.com/XXX/practiceLayui.git --allow-unrelated-histories
后面加上 --allow-unrelated-histories , 把两段不相干的 分支进行强行合并
这个时候git会让你必须输入点东西,记录这次你为什么要强行把远端的分支合并到本地
当你看到这样的语句后,push成功
上面是自己瞎提交研究的,其实git hub官网有完整的提交案例
直接在本地创建并初始化仓库,然后提交
echo "# practiceVue" >> README.md #这行我没敲也可以提交
git init
git add README.md
git commit -m "first commit"
git remote add origin https://github.com/XXX/practiceVue.git
git push -u origin master
这个XXX是自己的用户名,后面的master
就是要推上去的分支名
如果仓库已经在服务器上存在了,那么可以用下面这些命令提交
XXX也是自己的用户名
git remote add origin https://github.com/XXX/practiceVue.git
git push -u origin master