Git Bash上传文件

本文详细介绍了如何使用GitBash上传项目的步骤,包括初始化、添加文件、提交更改及远程仓库关联等。同时针对上传过程中可能遇到的问题给出了具体解决办法,如解决push失败的情况,并提醒用户注意及时pull远程更改。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

今天通过Git Bash上传了一个项目(之前是通过Github Desk上传的),操作命令如下:

在目录下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

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

2018.5.4

今天在上传代码过程中,最后一步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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值