正好今天遇到想把代码上传到Github,网上搜了一会,感觉这个方法最好用,记录一下:
具体带图的链接看:https://www.cnblogs.com/gushiren/p/9516319.html
总结就是:
先建新的仓库:create new repository
(如果没有配置过Git Setting的还需配置一下SSH Key,具体过程链接里有,这里只是一般步骤)
然后cd到指定文件夹
接着git clone https://github.com/SaltyFishX/Hysteresis-loop-XueJunjie.git(这里改成你的Git链接)
此时会生成以你仓库名为文件名的文件
然后将你想要上传的项目文件复制到上面的目录:
这一步很重要!比如你把你的项目git clone到D盘后,生成了一个新的项目文件夹,然后把你想上传的文件放到这个clone后的新的文件夹里。因为这个clone后的文件夹里包含了Readme.md,如果没有这么做的话后面push的时候可能会报错。
接着:
git init
git add “文件名”
git commit -m “文件名”
git remote add origin https://github.com/SaltyFishX/Hysteresis-loop-XueJunjie.git(你的Git链接)
如果出现错误:
fatal: remote origin already exists
则执行以下语句:
git remote rm origin
再执行git remote add origin https://github.com/SaltyFishX/Hysteresis-loop-XueJunjie.git即可。
git pull origin master
git push origin master
如果在push的时候报错,比如:failed to push some refs to git
说明你可能没有把想上传的文件放到clone后的文件夹。
两种补救方式:
https://jingyan.baidu.com/article/f3e34a12a25bc8f5ea65354a.html
https://blog.csdn.net/weixin_45784655/article/details/105565575
第二种方式比较粗暴,文件可能会丢
完成,再打开自己的仓库就会出现刚刚上传的项目文件: