Git创建新仓库并使用命令行上传到远程仓库

首先要在github上创建一个空的仓库,最好没有readme

在目录下shift+右键打开Git Bash

1.git init

2.git add *.py

3.git commit -m ‘first’

4.然后在Github上新建一个仓库add repository,输入仓库名和描述

5.远程关联仓库,git remote add origin git@github.com:hyqyoung(用户名)/yylc_jdpm(仓库名).git

6.开始上传文件git push -u origin master

如果第六步遇到问题:

fatal: ‘orign’ does not appear to be a git repository
fatal: Could not read from remote repository.

则先删除关联:git remote rm origin

然后再执行第五、六步,要注意的是这里命令不要用上下键去调用,可能不会更新原来的操作,需要手敲

最后一步push的时候报了如下错误:

To github.com:hyqyoung/yylc_jdpm.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'git@github.com:hyqyoung/yylc_jdpm.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.

原因是之前在GitHub的仓库里新建了一个README的文件,没有pull到本地。

所以在Github的远程仓库里做了一些变化的话,要及时pull到本地,代码:

git pull origin master
然后再进行1到6的步骤上传代码就可以了,

但是我原来做了一步不恰当的操作,那就是

git push -u origin master -f
强制执行,导致原来的远程仓库里的东西全部被替换掉了,所以切记这种操作是不可取的,并且尽量在本地做出一些修改,然后再push到GitHub上

转自 https://www.cnblogs.com/yqpy/p/8952170.html

创建一个全新的仓库

touch README.md
git init
git add README.md
git commit -m "first commit"
git remote add origin https://github.com/761472239/**.git
git push -u origin master

将一个已经存在的仓库上传到github

git remote add origin https://github.com/***/**.git
git push -u origin master

更新2019/9/22

在 创建远程仓库的时候报错
git push -u origin master
如下:
在这里插入图片描述
解决办法:https://blog.csdn.net/weixin_44394753/article/details/91410463

创建一个key
在这里插入图片描述

9/22 报错 添加文件名字过长

添加
git config --system core.longpaths true

下面是使用idea

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值