之前刚刚学会用GitHub管理代码的时候,总是很麻烦的要先在GitHub网页新建库,然后复制库链接,git clone到本地,然后add、commit、push一套下来,
大多数时候要把需要推送的文件放到一个新建的文件夹里,比较麻烦,而官方的帮助文档从来也没好好读过,有时候很不方便。
今天研究了一下,如何在现有的文件夹下,直接使用git bash推送到远程库。
这是官方给的新建库操作指令,加入我的注释:
//create a new repository on the command line
git init
git add README.md
git commit -m "first commit"
git branch -M main //将当前名为master的branch改名为main,这样做就会只有一个分支main,否则会有默认的分支master(什么也没传上去),和main分支。
git remote add origin git@github.com:Sandman6z/test.git
git push -u origin main
如果出现了如下提示:
! [rejected] main -> main (non-fast-forward)
error: failed to push some refs to 'github.com:Sandman6z/BLHeliSuite_OSs.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
那就从了他,pull一下吧。。。也不管用。
又查到其他大佬的操作,变成
git init
git add README.md
git commit -m "first commit"
git branch -M main
git remote add origin git@github.com:Sandman6z/test.git
git push -f origin master
//强制push(注意:不要随便用-f,会覆盖远端的所有代码)
在git bash中,自己尝试了很多不确定的东西,比如分支名、推送源(?)等等,下面是过程。
有很多蠢。B的指令,但是要自己亲自一步一步走一遍,才懂得怎么回事,全部贴出来给各位老哥参考。
这就是最终结果,只有一个分支,舒服。