git bash 从本地文件夹推送到远程库

之前刚刚学会用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的指令,但是要自己亲自一步一步走一遍,才懂得怎么回事,全部贴出来给各位老哥参考。

 

这就是最终结果,只有一个分支,舒服。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Sandman6z

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值